Q - Girls and Boys
来源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",n-ans);
}
return 0;
}
Q - Girls and Boys的更多相关文章
- 网络流(最大独立点集):POJ 1466 Girls and Boys
Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...
- POJ 1466 Girls and Boys
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- Girls and Boys
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hduoj-----(1068)Girls and Boys(二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ Girls and Boys (最大独立点集)
Girls and Boys Time Limit: 5000MS Memo ...
- poj 1466 Girls and Boys(二分图的最大独立集)
http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submis ...
- hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Girls and Boys(匈牙利)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- (hdu step 6.3.2)Girls and Boys(比赛离开后几个人求不匹配,与邻接矩阵)
称号: Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- 法嵌入互操作类型“SHDocVw.ShellWindowsClass”请改用适用的接口-解决方法
点DLL名字,---属性----------嵌入互操作类型(设置为false)
- kettle 6.1 日志查询
SELECT JB.ID_JOB, ---作业ID JB.NAME, ---作业名称 to_char(JB.DESCRIPTION) as JOB_DESCRIPTION , --作业描述 case ...
- Scikit-learn 概述
https://www.leiphone.com/news/201701/ZJMTak4Y8ch3Nwd0.html
- [Python设计模式] 第20章 挨个买票——迭代器模式
github地址:https://github.com/cheesezh/python_design_patterns 迭代器模式 迭代器模式,提供一种方法顺序访问一个聚合对象中各个元素,而又不暴露该 ...
- 分析轮子(四)- 我也玩一把 Serializable.java
前言:在写 分析轮子(一)-ArrayList.java 的时候曾经下过一个结论 “实现Serializable接口,表示ArrayList是可序列化的”,这个结论是以往学习的经验所得,并且平时在编程 ...
- Netty学习(八)-Netty的心跳机制
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/a953713428/article/details/69378412我们知道在TCP长连接或者Web ...
- Android 提高 gradle 的编译速度
随着项目在国内各个商店上线,开始介入了渠道的概念. 目前总共有 13 家商店,尝试使用 ./gradlew assembleRelease 命令打包,耗时将近 40 分钟. 因此搜索了一些可以提供编译 ...
- 关于asyncio知识(四)
一.使用 asyncio 总结 最近在公司的一些项目中开始慢慢使用python 的asyncio, 使用的过程中也是各种踩坑,遇到的问题也不少,其中有一次是内存的问题,自己也整理了遇到的问题以及解决方 ...
- 解决Eclipse中“诡异”的错误:找不到或无法加载主类
记录下来遇到的(问题,解决方法),是更有效的解决问题的方式.(原谅我领悟的太晚与懒,从此用更有意义的方法,做一个更有意义的人) 因为遇到了多次,参考同一个方法,原文连接:https://blog.cs ...
- MySQL高性能优化系列-目录
MySQL高性能优化系列-目录 (1)Mysql高性能优化规范建议 (2)电商数据库表设计 (3)MySQL分区表使用方法 (4)MySQL执行计划分析 (5)电商场景下的常见业务SQL处理 (6)M ...