制造测试数据的程序及对拍程序概述(Like CyaRon)
作为一名OIer,比赛时,对拍是必须的
不对拍,有时可以悔恨终身
首先,对拍的程序
一个是要交的程序
另一个可以是暴力、搜索等,可以比较慢,但是必须正确
下面是C++版对拍程序(C++ & cmd)
注意:所有程序不用加文件输入输出
#include<cstdio>
#include<cstdio>
#include<cstdlib>
#include<ctime>
int main()
{ long s,t;
while(1){
system("cls");
do{
system("data > data.in"); //data是数据生成程序
s=clock();
system("a.cpp < data1.in > data1.out"); //a是要交的程序
t=clock();
system("b.cpp < data2.in > data2.out"); //b是正确的程序
if(system("fc data1.out data2.out > nul"))
break;
else printf("AC time: %ldms\n",t-s);
}while(1);
printf("WA time: %ldms\n",t-s); //运行时间
system("fc data1.out data2.out");
system("pause>nul");
}
return 0;
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 [cpp] view plain copy
include<cstdio>
include<cstdlib>
using namespace std;
int main(){
for(int i=1;i<=1e5;i++){
#ifdef __linux
printf("You are on Linux!\n#####################\n");
system("./gen && ./sol && ./bf");
if(!system("diff tmpSol.out tmpBf.out"))
#endif
#ifdef _WIN32
printf("You are on Windows!\n#####################\n");
system("gen && sol && bf");
if(!system("fc tmpSol.out tmpBf.out"))
#endif
{
printf("Point #%d:\nAC~~ Ni GuoAK le~\n",i);
}
else{
printf("Point #%d:\nWA!! Ni Hoi U Jok Ba~\n",i);
break;
}
}
return 0;
}
0.简介:
在Python环境下,利用random,或洛谷研发的Cyaron都是不错的选择。
如果要使用Cyaron 请参见
Git-hub luogu-dev/cyaron
1.环境配置:
安装Python3及以上版本,在安装时选择自定义,勾选自动设置环境变量选项。当然能自己搞%%%
安装完成后打开命令提示符,输入python,如果进入Python环境就成功啦!!!
2.引入包:
想要使用random或cyaron,需要在程序开始引入包,类似于C++的头文件。
import random
from cyaron import *
1 2 如果你是第一次使用,需要安装cyaron。打开命令提示符输入以下命令即可。
pip install cyaron
1 3.格式化创建输入输出文件
fout = open("brick.in","w")
fout.close()
1 2 创建brick.in
for i in range(1,11):
fout = open("test%d.in"%i,"w")
fout.close()
py的range返回值是左闭右开的
1 2 3 4 创建test1.in~test10.in
4.输出
屏幕输出
for i in range(1,6):
for j in range(1,6):
print("%d %d\n"%(i,j))
1 2 3 py的%d,\n等用法类似C++
注意后半部分用%分割
样例输出
1 1 1 2 1 3 1 4 1 5 2 1 2 2 2 3 2 4 2 5 3 1 3 2 3 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 文件输出
接上一次的代码,向test1.in~test10.in中写入
for i in range(1,11):
fout = open("test%d.in"%i,"w")
fout.write("%d "%i)
fout.write的用法与print类似
fout.close()
1 2 3 4 5 5.生成数据
random
import random
fout = open("brick.in","w")
t = random.randint(1, 10)
fout.write("%d\n"%t)
for i in range(1,t+1):
n = random.randint(1, 100)
fout.write("%d\n"%n)
for j in range(1,n+1):
for k in range(1,n+1):
p=random.randint(1,2)
if p==1:
fout.write(".")
if p==2:
fout.write("#")
fout.write("\n")
fout.close()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 random有random.randint(l,r)函数,返回[l,r]之间的Int值。
样例输出:
5 23
.#.....####..######.#.
.#..#.##.##.##...##..#.
.###...##...#.#..#.
.#####.#......##...##.#
...###.####.#.##....###
.###.#.#.##.#..#...##..
..####..#.###......
..#.##..##.#.##.#..#.
.##.##.##..#......
....#.#....##.#.##.
...####...#.#.....#.###
.#.#...###..#.#...
.###..##..#.##.######.
..#.#..##....##.....
.#.#.##.#.###..#.##...#
.#..###.#.###..#..##.#.
..#.....##..###..#..#.
.#.#..######..##.#.####
..##.#...###.#.##.#.
....##.....#...##...
..#...#.##.###.......##
...#..#.##.###.###..##.
.#....#####..#.####.#.
25
..#.#.#####.##..##..#.
..#.#..##.#.#.#.#..###..#
..#.###.#####.#...##.
....#...#..##.#..##.#.
..##.##..#..##..####...
.#....#......##..#.#.###.
...##.##.....#..##.##...
.##..######.#.#..#####..#
.....#####.####.###..#.
.####...##...#.#.###.##..
.#..####..#.##...#.#.
..##....##..###.#.#.
......#.######.#..#...
.#.####..##.#.#.#..#.
..###.##.####.####..#..##
.####.#####..#..#.#.#....
.#.#.###.#.##.#..#####..#
.#...#.####.####.#..#.
..##...#.###.#...#.##.
..##..##.####..##..
.#.####.#..####....#####.
......###...##.##.#.##.
.#.#..#.##...###.##.#.
..#.##.#...##.#.#...#...
..##....#....####..##.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 数据太多不完全展示
6.对拍
对拍需要系统包
import os
1 OS命令用法与c++的system命令类似,都是引用系统命令提示符的命令
import os
while True:
os.system("a.exe")
os.system("b.exe")
os.system("fc a.out b.out")
1 2 3 4 5 当然你也可以用C++
#include <cstdlib>
using namespace std;
int main(){
while (1){
system("python mkdt.py");
system("a.exe");
system("b.exe");
system("fc a.out b.out");
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 对于不需要写文件输入输出的对拍Cyaron有更好的解决方案。它有自带的对拍函数可以引用。
7.Summary
当然了,上面的操作都是要设置好Python的环境变量的。
如果你对Python的基本语法还有不理解的地方,请参考luogu Python入门指南
作为一名OIer,比赛时,对拍是必须的
不对拍,有时可以悔恨终身
首先,对拍的程序
一个是要交的程序
另一个可以是暴力、搜索等,可以比较慢,但是必须正确
下面是C++版对拍程序(C++ & cmd)
注意:所有程序不用加文件输入输出
#include<cstdio>
#include<cstdio>
#include<cstdlib>
#include<ctime>
int main()
{ long s,t;
while(1){
system("cls");
do{
system("data > data.in"); //data是数据生成程序
s=clock();
system("a.cpp < data1.in > data1.out"); //a是要交的程序
t=clock();
system("b.cpp < data2.in > data2.out"); //b是正确的程序
if(system("fc data1.out data2.out > nul"))
break;
else printf("AC time: %ldms\n",t-s);
}while(1);
printf("WA time: %ldms\n",t-s); //运行时间
system("fc data1.out data2.out");
system("pause>nul");
}
return 0;
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 [cpp] view plain copy
include<cstdio>
include<cstdlib>
using namespace std;
int main(){
for(int i=1;i<=1e5;i++){
#ifdef __linux
printf("You are on Linux!\n#####################\n");
system("./gen && ./sol && ./bf");
if(!system("diff tmpSol.out tmpBf.out"))
#endif
#ifdef _WIN32
printf("You are on Windows!\n#####################\n");
system("gen && sol && bf");
if(!system("fc tmpSol.out tmpBf.out"))
#endif
{
printf("Point #%d:\nAC~~ Ni GuoAK le~\n",i);
}
else{
printf("Point #%d:\nWA!! Ni Hoi U Jok Ba~\n",i);
break;
}
}
return 0;
}
0.简介:
在Python环境下,利用random,或洛谷研发的Cyaron都是不错的选择。
如果要使用Cyaron 请参见
Git-hub luogu-dev/cyaron
1.环境配置:
安装Python3及以上版本,在安装时选择自定义,勾选自动设置环境变量选项。当然能自己搞%%%
安装完成后打开命令提示符,输入python,如果进入Python环境就成功啦!!!
2.引入包:
想要使用random或cyaron,需要在程序开始引入包,类似于C++的头文件。
import random
from cyaron import *
1 2 如果你是第一次使用,需要安装cyaron。打开命令提示符输入以下命令即可。
pip install cyaron
1 3.格式化创建输入输出文件
fout = open("brick.in","w")
fout.close()
1 2 创建brick.in
for i in range(1,11):
fout = open("test%d.in"%i,"w")
fout.close()
py的range返回值是左闭右开的
1 2 3 4 创建test1.in~test10.in
4.输出
屏幕输出
for i in range(1,6):
for j in range(1,6):
print("%d %d\n"%(i,j))
1 2 3 py的%d,\n等用法类似C++
注意后半部分用%分割
样例输出
1 1 1 2 1 3 1 4 1 5 2 1 2 2 2 3 2 4 2 5 3 1 3 2 3 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 文件输出
接上一次的代码,向test1.in~test10.in中写入
for i in range(1,11):
fout = open("test%d.in"%i,"w")
fout.write("%d "%i)
fout.write的用法与print类似
fout.close()
1 2 3 4 5 5.生成数据
random
import random
fout = open("brick.in","w")
t = random.randint(1, 10)
fout.write("%d\n"%t)
for i in range(1,t+1):
n = random.randint(1, 100)
fout.write("%d\n"%n)
for j in range(1,n+1):
for k in range(1,n+1):
p=random.randint(1,2)
if p==1:
fout.write(".")
if p==2:
fout.write("#")
fout.write("\n")
fout.close()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 random有random.randint(l,r)函数,返回[l,r]之间的Int值。
样例输出:
5 23
.#.....####..######.#.
.#..#.##.##.##...##..#.
.###...##...#.#..#.
.#####.#......##...##.#
...###.####.#.##....###
.###.#.#.##.#..#...##..
..####..#.###......
..#.##..##.#.##.#..#.
.##.##.##..#......
....#.#....##.#.##.
...####...#.#.....#.###
.#.#...###..#.#...
.###..##..#.##.######.
..#.#..##....##.....
.#.#.##.#.###..#.##...#
.#..###.#.###..#..##.#.
..#.....##..###..#..#.
.#.#..######..##.#.####
..##.#...###.#.##.#.
....##.....#...##...
..#...#.##.###.......##
...#..#.##.###.###..##.
.#....#####..#.####.#.
25
..#.#.#####.##..##..#.
..#.#..##.#.#.#.#..###..#
..#.###.#####.#...##.
....#...#..##.#..##.#.
..##.##..#..##..####...
.#....#......##..#.#.###.
...##.##.....#..##.##...
.##..######.#.#..#####..#
.....#####.####.###..#.
.####...##...#.#.###.##..
.#..####..#.##...#.#.
..##....##..###.#.#.
......#.######.#..#...
.#.####..##.#.#.#..#.
..###.##.####.####..#..##
.####.#####..#..#.#.#....
.#.#.###.#.##.#..#####..#
.#...#.####.####.#..#.
..##...#.###.#...#.##.
..##..##.####..##..
.#.####.#..####....#####.
......###...##.##.#.##.
.#.#..#.##...###.##.#.
..#.##.#...##.#.#...#...
..##....#....####..##.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 数据太多不完全展示
6.对拍
对拍需要系统包
import os
1 OS命令用法与c++的system命令类似,都是引用系统命令提示符的命令
import os
while True:
os.system("a.exe")
os.system("b.exe")
os.system("fc a.out b.out")
1 2 3 4 5 当然你也可以用C++
#include <cstdlib>
using namespace std;
int main(){
while (1){
system("python mkdt.py");
system("a.exe");
system("b.exe");
system("fc a.out b.out");
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 对于不需要写文件输入输出的对拍Cyaron有更好的解决方案。它有自带的对拍函数可以引用。
7.Summary
当然了,上面的操作都是要设置好Python的环境变量的。
如果你对Python的基本语法还有不理解的地方,请参考luogu Python入门指南
制造测试数据的程序及对拍程序概述(Like CyaRon)的更多相关文章
- [转]Linux/Windows下脚本对拍程序
[新]简单写法 (转载自:https://blog.csdn.net/ylsoi/article/details/79824655) 要求:文件输入输出,且输入输出文件需要对应 Linux: #inc ...
- acm对拍程序 以及sublime text3的文件自动更新插件auto refresh
acm等算法比赛常用---对拍 以及sublime text3的文件自动更新插件auto refresh 对拍 对拍即程序自动对比正确程序的运行结果和错误程序的运行结果之间的差异 废话少说, 直接上操 ...
- Mac OS下编写对拍程序
介绍 对拍是信息学竞赛中重要的技巧,它通过一个效率低下但正确率可以保证的程序,利用庞大的随机生成数据来验证我们的高级算法程序.对拍最大的优势在于可以通过人力所不能及的速度和数量达到验证的效果.下面我们 ...
- 手把手教你写对拍程序(PASCAL)
谁适合看这篇文章? ACMERS,OIERS或其它参加算法竞赛或需要算法的人 对操作系统并不太熟悉的人 不会写对拍的人 在网上找不到一个特别详细的对拍样例的人 不嫌弃我写的太低幼的人 前言 在NOIP ...
- ACM对拍程序
1.把所需对拍的代码的可执行文件a.exe b.exe放在同一目录下 2.把rand数据的代码的可执行文件c.exe放在该目录下 3.新建一个txt文件,里面添加代码,后把格式改成bat @echo ...
- [zt]手把手教你写对拍程序(PASCAL)
谁适合看这篇文章? ACMERS,OIERS或其它参加算法竞赛或需要算法的人 对操作系统并不太熟悉的人 不会写对拍的人 在网上找不到一个特别详细的对拍样例的人 不嫌弃我写的太低幼的人 前言 在NOIP ...
- 对拍程序 x
一.介绍 在做题或者正式比赛过程中总会把水题做水做乱,但因为样例有坑所以直接过了样例,然后拿去评测结果发现全WA.那如何在这种情况下检查自己程序或算法的正确性呢?对拍是一个简便省事的方案. 所谓“对拍 ...
- ACM 中的对拍程序
所谓对拍,就是随机生成数据,然后用一个肯定正确的暴力算法的程序,去测试一个要提交的程序. 由于比赛中一般使用 Linux 系统,所以本篇博客的代码都是 Linux 下的程序代码. 其实最简单的方式是写 ...
- Windows系统对拍程序
Windows系统对拍程序,其中包含c++11用法,请使用c++11标准编译.此对拍程序会在发现错误时显示错误行号以及对应内容,方便比对. 此对拍程序自动使用g++对源代码进行编译.如果出现找不到g+ ...
随机推荐
- 基于HTML5及WebGL的工控SCADA模拟飞机飞行
昨天看到一篇文章说是学习如何开飞机的,然后我就想,如果我也可以开飞机那就好玩了,每个人小时候都想做飞行员!中国飞行员太难当了,再说也不轻易让你开飞机!后来我就想如果能用 HT 开飞机那就是真的有趣了, ...
- linux环境下安装redis扩展
注意:目录的权限 chomd 777 -R 1.安装redis 下载:https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz 上传ph ...
- Hdu 1698(线段树 区间修改 区间查询)
In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroes. T ...
- hdu1285 确定比赛名次(拓扑排序)
有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道 ...
- centos 6.9安装zabbix 3.0
Linux下常用的系统监控软件有Nagios.Cacti.Zabbix.Monit等,这些开源的软件,可以帮助我们更好的管理机器,在第一时间内发现,并警告系统维护人员. 今天开始研究下Zabbix,使 ...
- 无阻赛的脚本(js脚本延迟方法)
js脚本的加载与执行 1.延迟脚本(defer属性) 带有defer属性的script标签,可以放置在文档的任何位置,在页面解析到该标签时,会开始下载该脚本,但是不会立即执行,直到dom加载完成(on ...
- Rem与Px的转换[转载]
原文:http://www.w3cplus.com/preprocessor/sass-px-to-rem-with-mixin-and-function.html rem是CSS3中新增加的一个单位 ...
- Page visibility 页面可见性
一直以来,判断页面是不是当前可见标签,浏览器有没有缩小都是比较麻烦的. 通过页面可见性API可以获得相关信息document.hidden 判断页面当前是不是可见的document.visibi ...
- css 权重 特殊性
选择器的特异性由 CSS2 规范定义如下: !important的规则比其他的权值都大 p{color: red !important} 如果声明来自于“style”属性,而不是带有选 ...
- MongoDB入门系列(一):基础概念和安装
概述 MongoDB是目前非常流行的一种非关系型数据库,作为入门系列的第一篇本篇文章主要介绍Mongdb的基础概念知识包括命名规则.数据类型.功能以及安装等. 环境: OS:Windows Versi ...