对拍程序

· · 个人记录

存一下对拍程序。

Shell

#!/bin/bash

export bf=./A-bf
export sol=./A-0
export random=./A-random
# 加 ./ 

test=1

g++ -O2 -std=c++14 -DLOCAL $bf.cpp -o $bf
g++ -O2 -std=c++14 -DLOCAL $sol.cpp -o $sol
g++ -O2 -std=c++14 -DLOCAL $random.cpp -o $random

while true
do
    $random > $sol.in
    $bf < $sol.in > $sol.ans
    $sol < $sol.in > $sol.out

    if diff $sol.out $sol.ans
    then
        echo "# $test : AC"
    else
        echo "# $test : WA"
        exit 0
    fi

    test=$(($test+1))
done

Windows

不需要 freopen!!!

Checker

包含判断 RE、WA、TLE,不同字体显示相应颜色,简单统计 TLE、RE 次数。

运行后先输入一个整数,表示测试组数。

#include<bits/stdc++.h>

using namespace std;

int test = 100500,TimeLimit = 1000;

int main() {
    int cnt_RE = 0,cnt_TLE = 0;
    long long Time = 0;

    for(int T = 1;T <= test; T++) {     
        system("random.exe > data.in");

        system("bf <data.in> data.ans");

        double st = clock();
        int Return = system("sol <data.in> data.out");
        double ed = clock();
        Time += ed - st;

        if(Return) {
            cout << "\033[35mRuntime Error\033[0m";
            printf(" Case #%d, Time :  %.0lfms\n",T,ed - st);
            system("msg hzoi RE!!!");

            cout << "return " << Return << "\n\n";
            cnt_RE ++;
            continue;
        }

        if(system("fc .\\data.out .\\data.ans > nul")) {
            cout << "\033[31mWrong Answer\033[0m";

            system("msg hzoi WA!!!");
            return 0;
        }
        else {
            if(ed - st > TimeLimit) {
                cout  << "\033[33mTime Limit Exceeded\033[0m";
                printf(" Case #%d, Time :  %.0lfms\n\n",T,ed - st);
                cnt_TLE ++;
            }
            else {
                cout  << "\033[32mAccepted\033[0m";
                printf(" Case #%d, Time :  %.0lfms\n\n",T,ed - st);
            }
        }
    }

    Time /= test;

    cout << "All tests " << test << " cases\n";
    cout << "Number of AC " << test - cnt_RE - cnt_TLE <<" times\n";
    cout << "Number of TLE " << cnt_TLE <<" times\n"; 
    cout << "Number of RE " << cnt_RE <<" times\n";
    cout << "Average of Time : " << Time << "ms" << "\n";
    return 0;
} 

Brute Force

#include <bits/stdc++.h>

using namespace std;

int main() {
    /*
     * Your Code
     */ 
    return 0;
}

Solution

#include <bits/stdc++.h>

using namespace std;

int main() {
    /*
     * Your Code
     */
    return 0;
}

Generator

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <ctime>
#include <cstdlib>

using namespace std;

int main() {
    srand((unsigned int)time(0));
    /*
     * Your Code
     */ 
    return 0;
}

Make Seed

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>

using namespace std;

const unsigned int mask = time(0);

unsigned int xor_shift(int x) {
    x ^= mask;
    x ^= x << 13;
    x ^= x >> 17;
    x ^= x << 5;
    x ^= mask;
    return x;
} 

int main() {
    unsigned int x;

    std::cin >> x;

    for(int i = 1;i <= 100; i++) {
        std::cout << (x = xor_shift(x)) << std::endl;
    }

    return 0;
}