今天下午出题的时候用了一下这两个黑科技2333,真的很舒服。
随机生成数据代码
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 int myrand(int mod) { return ((ll)rand()<<32^(ll)rand()<<16^rand())%mod; } 5 #define random(a, b)((a) + myrand((b) - (a) + 1)) //Integer[a,b] 6 int main(int argc, char *argv[]) { 7 stringstream ss; 8 int seed = time(NULL); 9 if (argc) { 10 ss << argv[1]; 11 ss >> seed; 12 } 13 srand(seed); 14 for(int j=1;j<=;++j){ 15 int n = random(1, 10); 16 int k = random(1, 1000); 17 assert(1 <= n && n <= 100); 18 assert(1 <= k && k <= 1000); 19 printf("%d %d ", n, k); 20 for (int i = 0; i < n; i++) { 21 int tmp = random(1, 100); 22 int tmp1=random(1,100); 23 cout<<tmp<<" "<<tmp1<<endl; 24 } 25 printf(" "); 26 } 27 return 0; 28 }
测定时间代码
1 clock_t start, end; 2 start = clock(); 3 end = clock(); 4 printf("run time: %lf ", (double)(end - start) / CLOCKS_PER_SEC);