作為一名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入門指南