这里转载汇总了三篇blog,谢谢原著者。。
ACM对拍程序过程。。。
一、用随机程序生成符合题目的输入数据文件名为in.txt
如何产生随机数:
http://www.cnblogs.com/lvsi/archive/2011/04/21/2024079.html
二、用AC的程序和你的程序分别跑数据in.txt
AC程序生成out1.txt 你的程序生成out2.txt
在生成输出数据的时候最好把输入的一些关键数据也一并输出,这样避免回头在in.txt中找对应的哪组输入是WA的数据
三、在两个输出数据的所在目录下新建一个txt 输入
fc out1.txt out2.txt
pause
另存为.bat的扩展格式。。。 最后运行这个bat文件就OK了。
fc 是file compare 的缩写,pause 是为了让比较结果停止以便查看。
fc 只显示每组差异中的第一行和最后一行,而不是显示所有不同的行。
所以在输出的时候不要输出太多的换行!!!
转载自Lvsi‘s home
===================================================================================================================
在做算法类竞赛的题目的时候,容易想到一个朴素的能保证完全正确的算法,但是会超时。而高效的算法又不能保证完全写对。这时候可以自己写一个朴素的算法、一个数据生成程序和一个文件比较程序进行验证高效算法的正确性。
在Windows下,fc命令提供了比较文件的功能,虽然批处理不如Linux下的bash等强大,但也足以写个自动比较的程序了。
随机数据的产生------C++ rand()用法:
rand()不需要参数,它会返回一个从0到最大随机数的任意整数,最大随机数的大小通常是固定的一个大整数。 这样,如果你要产生0~10的10个整数,可以表达为:
int N = rand() % 11;
这样,N的值就是一个0~10的随机数,如果要产生1~10,则是这样:
int N = 1 + rand() % 10;
总结来说,可以表示为:
a + rand() % n
其中的a是起始值,n是整数的范围。 a + rand() % (b-a+1) 就表示 a~b之间的一个随机数若要0~1的小数,则可以先取得0~10的整数,然后均除以10即可得到随机到十分位的10个随机小数,若要得到随机到百分位的随机小数,则需要先得到0~100的10个整数,然后均除以100,其它情况依此类推。
通常rand()产生的随机数在每次运行的时候都是与上一次相同的,这是有意这样设计的,是为了便于程序的调试。若要产生每次不同的随机数,可以包含time.h头文件,然后使用srand((unsigned)time(NULL))来使用当前时间使随机数发生器随机化,这样就可以保证每两次运行时可以得到不同的随机数序列。
批处理对拍程序:
1 :loop 2 make.exe > data.txt //make.exe是随机数据生成器程序 3 standard.exe < data.txt > std.txt //standard.exe标程程序 4 overtaking.exe < data.txt > ans.txt //overtaking.exe自己的程序 5 fc /A std.txt ans.txt 6 if not errorlevel 1 goto loop 7 pause
8 :end
命令行界面会不断提示找不到文件差异,然后就可以放心提交了,当然前提是你朴素的算法写对了。
==================================================================================
如何产生各种随机数
产生int型随机数
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
int main( )
{
//freopen( "1.in","r",stdin );
//freopen( "3.out","w",stdout );
srand( time( NULL ) );
int t,n = 10 ;
while( n-- )
{
printf("%d\n",rand() );
}
return 0;
}
产生随机小数
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
int main( )
{
//freopen( "1.in","r",stdin );
//freopen( "3.out","w",stdout );
srand( time( NULL ) );
int t,n = 10 ;
while( n-- )
{
printf("%.6lf\n",rand()*1.0 / 100 );
}
return 0;
}
产生任意范围的数
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
int main( )
{
//freopen( "1.in","r",stdin );
freopen("3.out","w",stdout );
srand( time( NULL ) );
int t = 99,n = 10 ;
while( n-- )
{
printf("%d\n",rand() % t );
}
return 0;
}
产生字符串
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
int main( )
{
//freopen( "1.in","r",stdin );
freopen("3.out","w",stdout );
srand( time( NULL ) );
int t = 99,n = 10 ;
while( n-- )
{
printf("%c\n",rand() % 26 + 'A' );
}
return 0;
}