跳到正文

个人记录

对拍程序

wangboyue_740325约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 3 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
void SetColorAndBackground(int ForgC, int BackC) {
	WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
void xy(int y,int x)
{
    COORD  coord;
    coord.X=x;
    coord.Y=y;
    HANDLE a=GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(a,coord);
}
void jdt(int x){
	xy(0,0);
	if(x==0){
		SetColorAndBackground(0,4);
		for(int i=1;i<=100;i++){
			cout<<"-";
		}
		SetColorAndBackground(15,0);
		cout<<"   "<<x<<"%\n";
		return;
	}
	if(x==100){
		SetColorAndBackground(0,2);
		for(int i=1;i<=100;i++){
			cout<<"=";
		}
		SetColorAndBackground(15,0);
		cout<<"   "<<x<<"%\n";
		return;
	}
	SetColorAndBackground(0,2);
	for(int i=1;i<x;i++){
		cout<<"=";
	}
	SetColorAndBackground(0,6);
	cout<<">";
	SetColorAndBackground(0,4);
	for(int i=x+1;i<=100;i++){
		cout<<"-";
	}
	SetColorAndBackground(15,0);
	cout<<"   "<<x<<"%\n";
	return;
}
const int N=5e5,M=20,K=20;
int main(){
	mt19937 rnd(time(0));
	jdt(0);
	for(int i=1;i<=100;i++){
		ofstream fout("tmp.in");
		int n=rnd()%N+1,m=rnd()%M+1,k=rnd()%K+1;
		fout<<n<<" "<<m<<" "<<k<<"\n";
		for(int i=1;i<=n;i++){
			if(rnd()%2){
				fout<<rnd()%n+1<<" ";
			}
			else{
				fout<<"0 ";
			}
		}
		fout.close();
		system("a.exe < tmp.in > tmp.out");
		system("b.exe < tmp.in > tmp.ans");
		if(system("fc tmp.out tmp.ans")){
			break;
		}
		jdt(i);
	}
	return 0;
}

将57~66行换成你的生成器。

原文