-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
73 lines (64 loc) · 2.06 KB
/
main.cpp
File metadata and controls
73 lines (64 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "normalSelect.hpp"
#include "select.hpp"
#include "MyRandom.hpp"
#include <iostream> //cin、cout
#include <string> //string
#include <stdio.h> //freopen
#include <vector>
#include <chrono>
using namespace std;
void make(int n);
int res1,res2,index;
long long int t1,t2, t3;
int main(){
int n = 1e6,k = 5e5;
//for(;n <= 10e9;n *= 10, k *= 10){
make(n);
freopen("in.txt", "r", stdin);
vector<int> vals;
vals.resize(n);
for(int i = 0;i < n;i++){
cin >> vals[i];
}
while(res1 == res2 && index < 100){
auto start = std::chrono::system_clock::now();
res1 = normalSelect(vals, k);
auto end = std::chrono::system_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
t1 += elapsed.count();
//freopen("out.txt", "w", stdout);
//cout << res << endl;
start = std::chrono::system_clock::now();
res2 = select(vals, k, 5);
end = std::chrono::system_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
t2 += elapsed.count();
//cout << res2 << endl;
start = std::chrono::system_clock::now();
res2 = select(vals, k, 3);
end = std::chrono::system_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
t3 += elapsed.count();
index++;
}
freopen("out.txt", "a", stdout);
cout << "级别:" << n << endl;
cout << "普通方法:" << t1 << endl;
cout << "改进方法5个一组:" << t2 << endl;
cout << "改进方法3个一组:" << t3 << endl;
t1 = 0;
t2 = 0;
t3 = 0;
index = 0;
//}
/*
return 0;
*/
}
void make(int n){
auto r = MyRandom(1, 1e5);
freopen("in.txt", "w", stdout);
for(int i = 0;i < n;i++){
cout << r.getWord() << " ";
}
}