zoukankan      html  css  js  c++  java
  • [ZOJ 1015]Fishing Net(MCS弦图的判定)

    Description

    In a highly modernized fishing village, inhabitants there make a living on fishery. Their major tools, fishing nets, are produced and fixed by computer. After catching fishes each time, together with plenty of fishes, they will bring back the shabby fishing nets, which might be full of leaks. Then they have to inspect those nets. If there exist large leaks, they have to repair them before launching out again.

    Obviously, the smaller the leaks in the fishing nets are, the more fishes they will catch. So after coming back, those fishermen will input the information of the fishing nets into the computer to check whether the nets have leaks.

    The checking principle is very simple: The computer regards each fishing net as a simple graph constructed by nodes and edges. In the graph, if any circle whose length (the number of edges) is larger than 3 must has at least one chord, the computer will output "Perfect" indicating that the fishnet has no leaks. Otherwise, "Imperfect" will be displayed and the computer will try to repair the net.

    Note: A circle is a closed loop, which starts from one node, passes through other distinct nodes and back to the starting node. A chord is an edge, which connects two different nodes on the circle, but it does not belong to the set of edges on the circle.

     

    Solution

    PE*1 QvQ

    Follow the output for each net with a blank line.

    弦图与区间图》CDQ

    最大势算法 Maximum Cardinality Search

    由n到1的顺序给点标号,设label[i]表示i与多少个已标号的点相连,每次选择label[i]最大的未标号点标号

    判断序列是否为完美消除

    设{vi+1,...,vn}中所有与vi相邻的点依次为vj1,...,vjk。只需判断vj1是否与vj2,...,vjk相邻即可。

    #include<iostream> 
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #define MAXN 1005
    using namespace std;
    int n,m,Map[MAXN][MAXN],label[MAXN],num[MAXN],visited[MAXN];
    void work()
    {
        for(int i=n;i>0;i--)
        {
            int u=0;
            for(int j=1;j<=n;j++)
            if(!visited[j]&&(!u||label[j]>label[u]))u=j;
            visited[u]=1;num[i]=u;
            for(int j=1;j<=n;j++)
            {
                if(Map[u][j]&&!visited[j])
                label[j]++;
            }
        }
    }
    bool judge()
    {
        for(int i=1;i<n;i++)
        {
            int t=i+1;
            while(t<=n&&!Map[num[i]][num[t]])t++;
            for(int j=t+1;j<=n;j++)
            {
                if(Map[num[i]][num[j]]&&!Map[num[t]][num[j]])
                return false; 
            }
        }
        return true;
    }
    int main()
    {
        while(~scanf("%d%d",&n,&m)&&n)
        {
            memset(Map,0,sizeof(Map));
            memset(label,0,sizeof(label));
            memset(visited,0,sizeof(visited));
            int u,v;
            for(int i=1;i<=m;i++)
            {
                scanf("%d%d",&u,&v);
                Map[u][v]=Map[v][u]=1;
            }
            work();
            if(judge())printf("Perfect
    ");
            else printf("Imperfect
    ");
            printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    Hadoop 最讨厌的报错:运行VirtualBox提示0x00000000错误“0x00000000指令引用的0x00000000内存该内存不能为written?
    linux下面/usr/local和opt目录有何区别
    Hadoop是不是必须在linux上运行?(根本原因是操作系统Linux的权限开放优势)
    Hadoop主要配置文件的作用
    RPC模式
    Hadoop安装最后一步~Hadoop伪分布式配置
    word 使用中遇到的小细节(按空格键后面字不见;从编译器粘贴的代码出现乱码,word标题内容折叠效果实现)
    在VS Code下配置Julia
    使用pandas读取csv文件和写入文件
    ModuleNotFoundError: No module named 'sklearn.cross_validation'
  • 原文地址:https://www.cnblogs.com/Zars19/p/6629517.html
Copyright © 2011-2022 走看看