码迷,mamicode.com
首页 > 其他好文 > 详细

数据生成程序

时间:2014-07-23 20:48:25      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   数据   io   

//数据生成程序
/*
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <set>
using namespace std;

int main() {
    int t = 999;
    srand( time(NULL) );
    freopen("e.txt","w",stdout);
    printf("%d\n",t);
    while(t--) {
        int n = rand() % 2000 + 1;
        int m = rand() % 1000 + 1;
        printf("%d %d\n", n, m);
        for(int i = 0; i < m; i++) {
            int x = rand() % n + 1;
            int y = rand() % n + 1;
            printf("%d %d\n",x, y);
        }
    }
}
*/

//标程
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

const int maxn = 2005;
int fa[maxn], r[maxn];

void init(int n)
{
    for(int i = 0; i <= n; i++)
    {
        fa[i] = i;
        r[i] = 0;
    }
}

int find(int x)
{
    if(fa[x] == x) return x;
    int fx = fa[x];
    fa[x] = find(fa[x]);
    r[x] = ( r[fx] + r[x] ) % 2;
    return fa[x];
}

void unin(int x, int y)
{
    int fx = find(x);
    int fy = find(y);
    if(fx != fy)
    {
        fa[fy] = fx;
        r[fy] = ( r[x] + r[y] + 1 ) % 2;
    }
}

int main()
{
    int t;
    int n, m;
    int a, b;
    freopen("e.txt","r",stdin);
    freopen("f.txt","w",stdout);
    scanf("%d",&t);
    for(int kase = 1; kase <= t; kase++)
    {
        bool flag = true;
        scanf("%d %d",&n, &m);
        init(n);
        for(int i = 0; i < m; i++){
            scanf("%d %d",&a, &b);
            if(!flag) continue;
            if(find(a) != find(b)) {
                unin(a, b);
            } else {
                if(find(a) == find(b) && r[a] == r[b]){
                    flag = false;
                }
            }
        }
        printf("Scenario #%d:\n", kase);
        if(flag) {
            puts("No suspicious bugs found!");
        } else {
            puts("Suspicious bugs found!");
        }
        if(kase != t) puts("");
    }
}

数据生成程序,布布扣,bubuko.com

数据生成程序

标签:style   blog   color   os   数据   io   

原文地址:http://www.cnblogs.com/zhanzhao/p/3863826.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!