zoukankan      html  css  js  c++  java
  • 数据生成程序

    //数据生成程序
    /*
    #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
    ",t);
        while(t--) {
            int n = rand() % 2000 + 1;
            int m = rand() % 1000 + 1;
            printf("%d %d
    ", n, m);
            for(int i = 0; i < m; i++) {
                int x = rand() % n + 1;
                int y = rand() % n + 1;
                printf("%d %d
    ",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:
    ", kase);
            if(flag) {
                puts("No suspicious bugs found!");
            } else {
                puts("Suspicious bugs found!");
            }
            if(kase != t) puts("");
        }
    }
  • 相关阅读:
    amd 2500 boot设置
    Windows Service开发日志(转载csdn)
    asp网站(asp+access)怎么防注入呢
    重新点亮shell————语法[四]
    重新点亮shell————特殊符号[五]
    Spring AOP及事务配置三种模式详解
    手撸一个IOC容器
    Mybatisplus入门教程
    Spring AOP源码解析
    深入理解Spring IOC容器及扩展
  • 原文地址:https://www.cnblogs.com/zhanzhao/p/3863826.html
Copyright © 2011-2022 走看看