跳到正文

个人记录

对拍 check 生成树

Forgive_Me约 2 分钟
原文
文章信息与版本

文章信息

发布
2023年1月14日
收录
2025年12月12日
更新
2026年10月25日
篇幅
约 2 分钟
获赞
2

版本

  1. v2当前
  2. v1

对拍 check

C++
#include<cstdio>
#include<cstdlib>
#include<ctime>

int main()
{   long s,t;
    while(1){
        system("cls");
        do{
            system("data > try.in"); //data是数据生成程序
            s=clock();
            system("a < try.in > try1.out");  //a是要交的程序
            t=clock();
            system("b < try.in > try2.out");  //b是正确的程序
            if(system("fc try1.out try2.out > nul"))
                break;
            else printf("AC time: %ldms\n",t-s);
        }while(1);
        printf("WA time: %ldms\n",t-s);  //运行时间
        system("fc try1.out try2.out");
        system("pause>nul");
    }
    return 0;
}

linux下同理,注意./a和diff的使用。

对拍生成树(n<=5)

C++
#include<bits/stdc++.h>
using namespace std;
int n,m,cnt,fa[100015];
int find(int x){
	return x==fa[x]?x:fa[x]=find(fa[x]);
}
int main()
{
	srand(time(0));
	n=rand()%5+1;
	cout<<n<<endl;
	cnt=0;
	for(int i=1;i<=n;i++)fa[i]=i;
	while(cnt<n-1){
		int x=rand()%n+1,y=rand()%n+1;
		int x1=find(x),y1=find(y);
		if(x1!=y1) fa[x1]=y1,cnt++,cout<<x<<" "<<y<<endl;
	}
}

或者随机 ii 向 [1,i−1][1,i-1] 连一条边。

纯随机:随机构造prufer序列,按照prufer序列生成一棵树。

原文
存档评论1 条抓取于