对拍
对拍要求
对拍需要至少3个程序,1个批处理。
3个程序中,其中一个是随机数生成器,用来生成输入数据(在这是r.cpp),输入数据一定是合法的,符合题目要求。
一个是暴力算法(暴力一定要保证正确),还有一个是你认为的正解
这三个程序不需要加文件输入输出。
编译运行这三个程序,把生成的exe文件和批处理放到一个文件夹里,运行批处理,如果两个程序输出不一样,那么批处理会自动关闭,这时查找输入的数据(在这是data.in),就是出错的输入数据,可以用它来调你的程序。
批处理内容(斜杠后是注释,使用时请删去)
:start //标号,用来goto循环执行批处理 r > data.in //产生输入数据 myself < data.in > myself.out //将输入数据输入到程序里,并产生输出文件 others < data.in > others.out //同上 fc myself.out others.out > nul //比较两个输出文件 if not errorlevel goto start //如果两个文件一样,再次执行批处理
对拍的作用:
考试时写出来了暴力,又想出来了一个可能对的正解,想判断正解的正确性,就可以用暴力的程序和它进行对拍。
想要保持AC率,可以用题解里的程序和你的程序对拍(但不要抄袭题解)
实例
以 UVA514 Rails为例(不要问我为什么以它为例)
随机数生成器
r.cpp
#include<windows.h>
#include<iostream>
#include<ctime>
bool tong[101];
using namespace std;
int main()
{
srand(time(0));
int n=rand()%101;
cout<<n<<endl;
for(int i=1;i<=n;)
{
int a=rand()%101;
if(!tong[a]&&a<=n&&a!=0)
{
i++;
tong[a]=1;
cout<<a<<" ";
}
}
cout<<endl<<0<<endl<<0;
return 0;
}我的程序
myself.cpp
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[],s[],t,flag=,n;
bool yyy;
void f()
{
flag=, t=;
for(int i=;i<=n;i++)
{
yyy=;
while(s[t]!=a[i]&&flag<=n)
{
s[++t]=flag;
flag++;
yyy=;
}
if(s[t]==a[i])
{
t--;
yyy=;
}
if(!yyy)
{
cout<<"No"<<endl;
return ;
}
}
cout<<"Yes"<<endl;
return ;
}
int main()
{
while()
{
cin>>n;
if(n==) break;
memset(a,,sizeof(a));
while()
{
cin>>a[];
if(a[]==) break;
for(int i=;i<=n;i++)
{
cin>>a[i];
}
f();
}
cout<<endl;
}
return ;
}题解的程序
others.cpp
#include<iostream>
#include<cstdio>
using namespace std;
#define maxn 10007
int n,k,a[maxn],s[maxn],top,q,x;
bool f()
{
k=,top=;
for(register int i=;i<=n;i++)
{
s[++top]=i;
while(top>&&s[top]==a[k])
{
k++;
top--;
}
}
if(top==) return ;
else return ;
}
inline void Init()
{
while()
{
scanf("%d",&q);
if(q==) break;
while()
{
scanf("%d",&x);
if(!x) break;
else a[]=x;
for(register int i=;i<=q;i++)
scanf("%d",&a[i]);
n=q;
if(f()) printf("Yes\n");
else printf("No\n");
}
printf("\n");
}
}
int main()
{
Init();
return ;
}批处理 对拍.bat
:start r > data.in myself < data.in > myself.out others < data.in > others.out fc myself.out others.out > nul if not errorlevel goto start
如果输出不一样,窗口会自动关闭,在这因为程序都是对的,所以它会一直滚动。
相关推荐
smalllove 2020-11-03
wuhuaguwuhuaguo 2020-09-15
guying 2020-08-16
wqcong 2020-06-14
chenzhiwei 2020-06-13
talkingDB 2020-05-05
83206837 2020-05-01
Yasin 2020-03-03
Amzaing00 2020-01-06
GechangLiu 2020-01-05
shenghua 2013-03-27
文山羊 2019-12-16
乾坤一碼農 2019-12-11
dongxurr 2019-12-09
bluestartlxp 2019-11-27
86427217 2015-04-18
thankinglove 2015-09-06
圆圆的世界CSDN 2019-11-07
longxiang 2010-04-07