本文整理汇总了C++中Answer::maxSlidingWindow方法的典型用法代码示例。如果您正苦于以下问题:C++ Answer::maxSlidingWindow方法的具体用法?C++ Answer::maxSlidingWindow怎么用?C++ Answer::maxSlidingWindow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Answer
的用法示例。
在下文中一共展示了Answer::maxSlidingWindow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[]) {
Test test;
Solution sol;
Answer ans;
chrono::time_point<chrono::system_clock> ts0, ts1, ts2, ts3, ts4;
ofstream outfile;
outfile.open("output.txt");
ts0 = std::chrono::system_clock::now();
vector<int> tin = test.generate();
ts1 = std::chrono::system_clock::now();
vector<int> touts = sol.maxSlidingWindow(tin, TK);
ts2 = std::chrono::system_clock::now();
vector<int> touta = ans.maxSlidingWindow(tin, TK);
ts3 = std::chrono::system_clock::now();
if (touts.size() != touta.size()) {
cout << "Error, solution size not equal" << endl;
return -1;
} else {
for(int i=0; i<touts.size(); i++) {
if (touts[i] != touta[i]) {
cout << "Error, solution vector item: " << i << " not equal" << endl;
return -2;
} else {
outfile << touts[i] << endl;
}
}
}
ts4 = std::chrono::system_clock::now();
chrono::duration<double> e10 = ts1-ts0;
chrono::duration<double> e21 = ts2-ts1;
chrono::duration<double> e32 = ts3-ts2;
chrono::duration<double> e43 = ts4-ts3;
cout << argv[0] << " All test passed ~" << endl;
cout << argv[0] << " Elapsed time generate test case: " << e10.count() << endl;
cout << argv[0] << " Elapsed time my solution O(N): " << e21.count() << endl;
cout << argv[0] << " Elapsed time official O(N) answer: " << e32.count() << endl;
cout << argv[0] << " Elapsed time comparison result: " << e43.count() << endl;
outfile.close();
return 0;
}