C++随机数及对拍
先說隨機數:
mt19937_64 eng(time(NULL));//重置種子 uniform_int_distribution<long long>ran(-10000000000,10000000000);//自行設置范圍 cout<<ran(eng)<<endl;//調用隨機數C++11的隨機數,比rand更好用,但相應的這個單詞更難背。。(英語渣)
再說對拍:
#include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<climits> #include<queue> #include<map> #include<set> #include<sstream> #include<cassert> #include<bitset> #include<unordered_map> using namespace std;typedef long long LL;typedef unsigned long long ull;const int inf=0x3f3f3f3f;const int N=2e5+100;int main() { #ifndef ONLINE_JUDGE // freopen("data.in.txt","r",stdin); // freopen("data.out.txt","w",stdout); #endif // ios::sync_with_stdio(false);for(int i=1;i<=10000;i++)//樣例組數{system("random.exe");//先生成隨機數到data.indouble st=clock();system("未命名1.exe");//調用自己的錯誤程序:data.in->data.outdouble ed=clock();system("未命名2.exe");//調用自己的正確程序(暴力):data.in->data.ansif(system("fc data.out.txt data.ans.txt"))//判斷data.out和data.ans是否一致{puts("Wrong Answer");return 0;}elseprintf("Accepted, 測試點 #%d, 用時 %.0lfms\n",i,ed-st);}return 0; }未命名一中加上:
freopen("data.in.txt","r",stdin);freopen("data.out.txt","w",stdout);未命名二中加上:
freopen("data.in.txt","r",stdin);freopen("data.ans.txt","w",stdout);隨機數中加上:
freopen("data.in.txt","w",stdout);以上操作皆用于程序與文件的互動
總結
- 上一篇: 牛客 - 红蓝图(克鲁斯卡尔重构树的df
- 下一篇: 洛谷 - P2761 软件补丁问题(sp