zoukankan      html  css  js  c++  java
  • Q

    来源poj1068

    In the second year of the university somebody started a study on the romantic relations between the students. The relation "romantically involved" is defined between one girl and one boy. For the study reasons it is necessary to find out the maximum set satisfying the condition: there are no two students in the set who have been "romantically involved". The result of the program is the number of students in such a set.

    Input

    The input contains several data sets in text format. Each data set represents one set of subjects of the study, with the following description:

    the number of students
    the description of each student, in the following format
    student_identifier:(number_of_romantic_relations) student_identifier1 student_identifier2 student_identifier3 ...
    or
    student_identifier:(0)

    The student_identifier is an integer number between 0 and n-1 (n <=500 ), for n subjects.

    Output

    For each given data set, the program should write to standard output a line containing the result.

    Sample Input

    7
    0: (3) 4 5 6
    1: (2) 4 6
    2: (0)
    3: (0)
    4: (2) 0 1
    5: (1) 0
    6: (2) 0 1
    3
    0: (2) 1 2
    1: (1) 0
    2: (1) 0

    Sample Output

    5
    2

    最大独立集合,但要男女,而男女没有给出,所以会重复,要除2;点数-最大匹配数/2

    #include<iostream>
    #include<stdio.h>
    #include<stdlib.h>
    #include <iomanip>
    #include<cmath>
    #include<float.h> 
    #include<string.h>
    #include<algorithm>
    #define sf scanf
    #define pf printf
    #define mm(x,b) memset((x),(b),sizeof(x))
    #include<vector>
    #include<queue>
    #include<map>
    #define rep(i,a,n) for (int i=a;i<n;i++)
    #define per(i,a,n) for (int i=a;i>=n;i--)
    typedef long long ll;
    const ll mod=1e9+100;
    const double eps=1e-8;
    using namespace std;
    const double pi=acos(-1.0);
    const int inf=0xfffffff;
    const int N=1005;
    int n,m,x,y;
    int pre[N],line[N][N],visit[N],connect[N];
    bool find(int x)
    {
    	rep(i,1,n+1)
    	{
    		if(visit[i]==0&&line[x][i])
    		{
    			visit[i]=1;
    			if((pre[i]==0||find(pre[i]))&&pre[i]!=x)
    			{
    				pre[i]=x;
    				return true;
    			}
    		}
    	}
    	return false;
    }
    //int deal()
    //{
    //	int ans=0;
    //	rep(i,1,n+1)
    //	{
    //		if(pre[pre[i]]==i)
    //		{
    //			ans++;
    //			pre[i]=-1;
    //		}
    //	}
    //	return ans;
    //}
    int main()
    {
    	while(~sf("%d",&n))
    	{
    		mm(line,0);
    		mm(pre,0);
    		rep(i,1,n+1)
    		{
    			int p;	
    			sf("%d: (%d)",&x,&p);
    			while(p--)
    			{
    				sf("%d",&y);
    				line[x+1][y+1]=1;
    			}
    		}
    		int ans=0;
    		rep(i,1,n+1)
    		{
    			mm(visit,0);
    			if(find(i)) ans++;
    		}
    		ans/=2;
    	//	ans+=deal();
    		pf("%d
    ",n-ans);
    	}
    	return 0;
     } 
    
  • 相关阅读:
    C# 停止或开启服务
    微软企业库 缓存
    C# 获取图片一部分
    [转载]MVC3在win 2003虚拟主机上的调试
    mongodb查询的语法
    Mongodb亿级数据量的性能测试比较完整收藏一下
    正则验证数字
    收到了Gmail的Beta测试邀请
    C#新手经验点滴
    Windows消息机制
  • 原文地址:https://www.cnblogs.com/wzl19981116/p/9458638.html
Copyright © 2011-2022 走看看