對拍

AuroraKelsey發表於2024-11-14

c++

duipai.cpp

#include <bits/stdc++.h>  
using namespace std;  
  
int main(){  
    for(int i=0;i<100000;i++){  
       system("mk");  // ./mk
       system("baoli < in.txt > baoli.out");  
       system("std < in.txt > std.out");  
       if(system("fc baoli.out std.out")){  //linux/mac diff
          printf("%d !!!!!!!!",i);  
          while(1);  
       }  
    }  
    return 0;  
}

mk.cpp

#include <cstdio>  
#include <cstdlib>  
#include <algorithm>  
  
using namespace std;  
  
int main(){  
    int seed;  
    freopen("seed.txt", "r", stdin);  
    scanf("%d",&seed);  
  
    srand(seed+time(0));  
    for(int i=0;i<5;i++) rand();  
  
    freopen("seed.txt","w",stdout);  
    printf("%d\n", rand());  
  
    freopen("in.txt","w",stdout);  
    printf("%d %d\n",rand()%100,rand()%100);  
  
    return 0;  
}

mk_graph.cpp

#include <cstdio>  
#include <ctime>  
#include <algorithm>  
  
using namespace std;  
int vis[1000][1000];  
const int N=1e6+10;  
int main(){  
    int seed;  
    freopen("seed.txt", "r", stdin);  
    scanf("%d",&seed);  
  
    srand(seed+time(0));  
    for(int i=0;i<5;i++) rand();  
  
    freopen("seed.txt","w",stdout);  
    printf("%d\n", rand());  
  
    freopen("in.txt","w",stdout);  
    int t=rand()%10;  
    while(t--){  
        int n=rand()%N;  
        int m=rand()%(5*N);  
        printf("%d %d\n",n,m);  
        for(int i=1;i<=n;i++)  
            printf("%d ",rand()%10000);  
        for(int i=1;i<=m;i++){  
          int x=1,y=1;  
          while(x==y || vis[x][y]){  
             x = rand()%n+1;  
             y = rand()%n+1;  
          }  
          vis[x][y] = vis[y][x] = 1;// wuxiangtu  
          printf("%d %d\n",x,y);  
  
       }  
    }  
    return 0;  
}

python

測試資料
luogu-dev/cyaron: CYaRon: Yet Another Random Olympic-iNformatics test data generator (github.com)

例子

main.py

import os  
  
def run():  
    os.system('python mk.py')  
    os.system('python my.py < in.txt > my.txt')  
    os.system('python std.py < in.txt > std.txt')  
  
  
def check():  
    my = open('my.txt', 'r')  
    std = open('std.txt', 'r')  
    log = open('log.txt', 'w')  
    log.write('-----------All Error-----------\n')  
    # 這個i能記錄順序  
    for i, (a, b) in enumerate(zip(my, std)):  
        if a != b:  
            log.write('line:' + str(i + 1) + '\n')  
            log.write('-----my:' + a)  
            log.write('-----std:' + b)  
  
  
if __name__ == '__main__':  
    run()  
    check()

mk.py

import random  
import string  
out = open('in.txt', 'w')  
out.write(str(random.randint(-1000,1000))+'\n')  
out.write(str(random.randint(-1000,1000))+'\n')  
out.close()

my.py

a = int(input())  
b = int(input())  
for x in range(0, a):  
    b += 1  
print(b)

std.py

a = int(input())  
b = int(input())  
print(a+b)

構造隨機數

from random import *  
import string  
  
print('隨機生成一個整數', randint(-10000000, 10000000))  
# 返回指定遞增基數集合中的一個隨機數 randrange ([start=1,] stop [,step=1])print('隨機生成一個偶數', randrange(0, 10000000, 2))  
  
print('隨機浮點數', uniform(0, 100))  
# 在指定字元中生成一個隨機字元  
# choice(seq)從非空序列 seq 中隨機選擇一個元素  
print('隨機字元', choice(string.ascii_letters))  
"""  
String模組中的常量:  
string.digits:數字0~9  
string.ascii_letters:所有字母(大小寫)  
string.lowercase:所有小寫字母  
string.printable:可列印字元的字串  
string.punctuation:所有標點  
string.uppercase:所有大寫字母  
"""  
# 在指定字元中生成指定數量的隨機字元  
print(sample(string.ascii_letters + string.digits, 5))  
  
# str.join(seq) 將序列中的元素以str間隔連線生成一個新的字串  
ran_str = ''.join(sample(string.ascii_letters + string.digits, 5))  
print('隨機字串', ran_str)  
ran_str2 = ','.join(sample(string.ascii_letters + string.digits, 5))  
print('隨機字串', ran_str2)

\(mk.py\)

import random  
import string  
out = open('in.txt', 'w')  
out.write(str(random.randint(-1000,1000))+'\n')  
out.write(str(random.randint(-1000,1000))+'\n')  
out.close()

打亂陣列的順序

items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]  
shuffle(items)  
for i in range(0, len(items)):  
    print(items[i], " ", end='')

計算時間

單位為秒

import time  
time_start = time.time()  
# 程式  
time_end = time.time()  
print(time_end-time_start)

相關文章