对拍 check 生成树

· · 个人记录

对拍 check

#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)

#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;
    }
}

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

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