对拍
来源:互联网 发布:99宿舍网络加速器 编辑:程序博客网 时间:2024/04/19 13:29
将以下四个程序放进一个文件夹中,并且凡是cpp的文件都要运行出来exe文件,.bat文件是用text文本写的,将.txt扩展名改为.bat,最后双击.bat即可弹出黑色窗口,显示测试结果。第一个program1.cpp是时间复杂度较高的程序,结果肯定是正确的,一般用简单暴力来写,program2是时间复杂度较低的文件,按照正解的要求去写的程序,目的是比较program2,检验其结果的正确性。
CreatRand.cpp的程序
#include<iostream>#include<time.h>#include<cstdlib>using namespace std;int main(){ freopen("in.txt","w",stdout); srand((unsigned)time(NULL)); int n; n=rand()%90000; cout<<n<<endl; for(int i=1;i<=n;i++) cout<<rand()%1000<<" "; cout<<endl; }
test.bat程序
@echo off:startCreatRandprogram1program2fc out1.txt out2.txt if not errorlevel 1 goto startpause:end
也可以写一个cpp:
#include<ctime> #include<cstdlib>int main(){ int i,j; srand(time(0)); while(1) { system("CreatRand.exe"); system("program1.exe"); system("program2.exe"); if(system("fc out1.txt out2.txt")) while(1); }}
program1程序:
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int a[400005],f[400005],pre[400005];int n,mx,mx2,last;int main(){ freopen("in.txt","r",stdin); freopen("out1.txt","w",stdout); cin>>n; memset(pre,0xffffffff,sizeof pre); for(int i=1;i<=n;i++) cin>>a[i],f[i]=1; for(int i=2;i<=n;i++) { mx=0; for(int j=1;j<i;j++) { if(a[i]>a[j] && f[j]>mx) { mx=f[j]; pre[i]=j; f[i]=mx+1; } } } for(int i=1;i<=n;i++) if(f[i]>mx2) mx2=f[i],last=i; cout<<mx2<<endl;// for(int i=last;i!=-1;i=pre[i])// cout<<a[i]<<"<-";// cout<<"start";}
program2的程序:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int N = 410000; int a[N]; //a[i] 原始数据 int d[N]; //d[i] 长度为i的递增子序列的最小值 int BinSearch(int key, int* d, int low, int high) { while(low<=high) { int mid = (low+high)>>1; if(key>d[mid] && key<=d[mid+1]) return mid; else if(key>d[mid]) low = mid+1; else high = mid-1; } return 0; } int LIS(int* a, int n, int* d) { int i,j; d[1] = a[1]; int len = 1; //递增子序列长度 for(i = 2; i <= n; i++) { if(d[len]<a[i]) j = ++len; else j = BinSearch(a[i],d,1,len) + 1; d[j] = a[i]; } return len; //最后输出长度 } int main() { freopen("in.txt","r",stdin); freopen("out2.txt","w",stdout); int p; scanf("%d",&p); for(int i = 1; i <= p; i++) scanf("%d",&a[i]); int zlen=LIS(a,p,d); printf("%d\n",zlen);}
这张图片显示了一个有问题的程序program3,因此最后会输出比较有差异的结果。此时,你可以去找文件夹里的in.txt输入文件,从而查找错误原因。
0 0
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- Unbuntu下修复Windows 10引导
- 网页布局基础之盒子模型与浮动
- 使用Xutils3.0 进行上传和下载数据
- 移位密码
- lua中实现switch以及sublime下自动补全switch语法
- 对拍
- sublime自定义补全关键字 导出工具
- Poj 2391 Ombrophobic Bovines【二分+最大流Dinic】
- Android Studio使用Volley
- zznu 1992 (dp + 01双背包)
- HIHO #1297 : 数论四·扩展欧几里德
- IDEA artifacts 详细部署
- ReactNative: 记录几个常用
- Mac下Jenkins+SVN+Xcode构建持续导出环境