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;
     } 
    
  • 相关阅读:
    Scheduler踩坑记录
    关于RedisTemplate的map存储踩坑记录
    关于HashMap的加载因子相关理解
    Mybatis 分页插件PageHelper 遇坑
    Linux 下 Mysql忘记密码重置
    Eclipse MAT和jvisualvm分析内存溢出
    使用jdk自带工具jvisualvm 分析内存dump文件
    EUREKA 删除 or 强制下线/上线 实例
    Idea 远程调试jenkins 项目
    spring 事务传播行为类型
  • 原文地址:https://www.cnblogs.com/wzl19981116/p/9458638.html
Copyright © 2011-2022 走看看