对拍和随机数据生成

c++ 对拍

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
#include<ctime>
using namespace std;
typedef long long ll;
int main()
{
    for(int t = 1;t <= 100000;t ++){
        system("E:\\noip\\random.exe");
        double st = clock();
        system("E:\\noip\\1.exe");
        double en = clock();
        system("E:\\noip\\2.exe");
        if(system("fc E:\\noip\\data.out E:\\noip\\data.ans")){
            cout<<"WA"<<endl;return 0;
        }   
        else {
            cout<<"AC"<<endl;
            printf("%.0lfms\n",en - st);    
        }
    }
    return 0;
}

随机生成图

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
#include<ctime>
#include<map>
using namespace std;
typedef long long ll;
pair <int,int> e[10011];
map < pair<int,int> ,bool> h;
ll random(ll n){
    return (ll)rand()*rand()%n;
}
int main()
{
    freopen("data.in","w",stdout);
    srand(time(0));
    int n = 500,m = 10001;
    cout<<n<<" "<<m<<endl;
    for(int i = 1;i < n;i ++){
        int fa = random(i) + 1;
        e[i] = make_pair(fa,i + 1);
        h[e[i]] = h[make_pair(i,fa)] = 1;
    }
    for(int i = n;i <= m;i ++){
        int x,y;
        do{
            x = random(n) + 1,y = random(n) + 1;
        }while(x == y || h[make_pair(x,y)]);
        e[i] = make_pair(x,y);
        h[e[i]] = h[make_pair(y,x)] = 1;
    }
    for(int i = 1;i <= m;i ++){
        printf("%d %d\n",e[i].first,e[i].second);
    }
    return 0;
}

随机生成树

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
#include<ctime>
#include<map>
using namespace std;
typedef long long ll;
pair <int,int> e[10011];
map < pair<int,int> ,bool> h;
ll random(ll n){
    return (ll)rand()*rand()%n;
}
int main()
{
    freopen("data.in","w",stdout);
    srand(time(0));
    int n = 500;
    cout<<n<<endl;
    for(int i = 1;i < n;i ++){
        int fa = random(i) + 1;
        cout<<fa<<" "<<i + 1<<endl;
    }
    return 0;
}

原文链接: https://www.cnblogs.com/wtz2333/p/12233135.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    对拍和随机数据生成

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/324884

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月1日 下午3:06
下一篇 2023年3月1日 下午3:07

相关推荐