专栏文章

How to 对拍?

个人记录参与者 1已保存评论 0

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
0 条
当前快照
1 份
快照标识符
@miqvl99e
此快照首次捕获于
2025/12/04 11:27
3 个月前
此快照最后确认于
2025/12/04 11:27
3 个月前
查看原文
主要分成三个文件:
generator.cpp: 用来生成随机数
brute.cpp: 暴力代码(保证正确)
code.cpp: 待检验代码
duipai.cpp: 用来对拍
如果用A+BA+B problemproblem举例:
generator.cpp:
CPP
#include<bits/stdc++.h>
#include<ctime>
using namespace std;
int main() {
    srand(time(0));
    int a, b;
    
    for(int i=1;i<=20;i++)
	{
		a=(1ll * rand() * RAND_MAX+rand() )%200000;
		b=(1ll * rand() * RAND_MAX+rand() )%200000;
		printf("%d %d\n", a,b);
	} 
    return 0;
}
brute.cpp
CPP
#include <bits/stdc++.h>
using namespace std;

int main() {
    int a, b;
    cin>>a>>b;
    cout<<a+b<<endl;
    return 0;
}

code.cpp
CPP
#include <bits/stdc++.h>
using namespace std;

int main() {
    srand(time(0));
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", a+b);
    return 0;
}
duipai.cpp
CPP
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <windows.h>
#include <cstdlib>
#include <ctime>
#define WHITE "\033[37m"
#define RED   "\033[31m"
#define YELLOW   "\033[33m"
#define GREEN   "\033[32m"
#define RESET "\033[0m"
using namespace std;

int main() {
    int expected = 0, verdict = 0,ok=0,maxt,nok=0,ans;
    printf("Input number of test cases: ");
    scanf("%d", &expected);
    printf("Input number of test max time: ");
    cin>>maxt;
    for(int test_case=1;test_case<=expected;test_case++) {
        cout<<RESET;
		printf("Running on test #%d: ", test_case);
        system("generator > 1.in");
        system("code < 1.in > 1.out");
        double begin = clock();
        system("brute < 1.in > 1.ans");
        double end = clock();

        double t = (end - begin);
        if(verdict==1)
        {
        	cout<<RESET<<WHITE<<"Skip this test point"<<endl;
        	continue;
		}
        else if(t>maxt)
        {
        	cout<<YELLOW<<"Time Limited Exceeded on test"<<test_case<<" use "<<t<<" ms\n";
        	continue;
		}
        else if(system("fc 1.out 1.ans > 1.log" ) and t<=maxt) {
            cout<<RED<<"Wrong Answer on test "<<test_case<<" use "<<t<<" ms\n";
            if(MessageBox(NULL,"Wrong Answer! Did you want to break?","break?",MB_YESNO|MB_ICONQUESTION)==IDYES)
            {
            	verdict = 1;
            	ans=test_case;
            	continue;
			}
			verdict = 0;
            nok++;
            continue;
        }
        
        cout<<GREEN<<"Accepted on test "<<test_case<<" use "<<t<<" ms\n";
        ok++;
    }
    cout<<RESET;
    if(verdict)
    {
    	cout<<YELLOW<<"You skip test on running test "<<ans<<endl;
    	cout<<"You can debug!";
    	return 0;
	}
    cout<<GREEN<<"AC:"<<ok<<"/"<<expected<<RESET<<RED<<"   WA:"<<nok<<"/"<<expected<<YELLOW<<"   TLE:"<<expected-ok-nok<<"/"<<expected<<endl<<RESET;
    
	if(float(ok*100.0/expected)<60)
    {
    	cout<<RED;
	}
	else if(float(ok*100.0/expected)<=80)
	{
		cout<<YELLOW;
	}
	else  cout<<GREEN;
    cout<<"score:"<<float(ok*100.0/expected);
    return 0;
}

评论

0 条评论,欢迎与作者交流。

正在加载评论...