POJ 2771 二分图(最大独立集)
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 5244 | Accepted: 2192 |
Description
- Their height differs by more than 40 cm.
- They are of the same sex.
- Their preferred music style is different.
- Their favourite sport is the same (they are likely to be fans of different teams and that would result in fighting).
So, for any two persons that he brings on the excursion, they must satisfy at least one of the requirements above. Help him find the maximum number of persons he can take, given their vital information.
Input
- an integer h giving the height in cm;
- a character 'F' for female or 'M' for male;
- a string describing the preferred music style;
- a string with the name of the favourite sport.
No string in the input will contain more than 100 characters, nor will any string contain any whitespace.
Output
Sample Input
2
4
35 M classicism programming
0 M baroque skiing
43 M baroque chess
30 F baroque soccer
8
27 M romance programming
194 F baroque programming
67 M baroque ping-pong
51 M classicism programming
80 M classicism Paintball
35 M baroque ping-pong
39 F romance ping-pong
110 M romance Paintball
Sample Output
3
7
Source
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
using namespace std; #define N 505 int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int abs(int x,int y){return x<?-x:x;} int n, m;
bool visited[N];
vector<int>ve[N];
int from[N]; struct node{
int h;
char sex[];
char music[];
char sport[];
}a[N]; int march(int u){
int i, j, k, v;
for(i=;i<ve[u].size();i++){
v=ve[u][i];
if(!visited[v]){
visited[v]=true;
if(from[v]==-||march(from[v])){
from[v]=u;
return ;
}
}
}
return ;
} main()
{
int t, i, j, k;
cin>>t;
while(t--){
scanf("%d",&n);
for(i=;i<n;i++){
scanf("%d%s%s%s",&a[i].h,a[i].sex,a[i].music,a[i].sport);
}
for(i=;i<=n;i++) ve[i].clear();
for(i=;i<n;i++){
if(a[i].sex[]=='F'){
for(j=;j<n;j++){
if(a[j].sex[]=='M'){
if(abs(a[i].h-a[j].h)<=&&strcmp(a[i].music,a[j].music)==&&strcmp(a[i].sport,a[j].sport)){
ve[i].push_back(j);
}
}
}
}
} int num=;
memset(from,-,sizeof(from));
for(i=;i<n;i++){
memset(visited,false,sizeof(visited));
if(march(i)) num++;
}
printf("%d\n",n-num);
}
}
POJ 2771 二分图(最大独立集)的更多相关文章
- Poj(2771),最大独立集
题目链接:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K To ...
- Girls and Boys POJ - 1466 【(二分图最大独立集)】
Problem DescriptionIn the second year of the university somebody started a study on the romantic rel ...
- Guardian of Decency POJ - 2771 【二分匹配,最大独立集】
Problem DescriptionFrank N. Stein is a very conservative high-school teacher. He wants to take some ...
- POJ 3692 Kindergarten(二分图最大独立集)
题意: 有G个女孩,B个男孩.女孩彼此互相认识,男孩也彼此互相认识.有M对男孩和女孩是认识的.分别是(g1,b1),.....(gm,bm). 现在老师要在这G+B个小孩中挑出一些人,条件是这些人都互 ...
- poj——2771 Guardian of Decency
poj——2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5916 ...
- HDU 3829 - Cat VS Dog (二分图最大独立集)
题意:动物园有n只猫和m条狗,现在有p个小孩,他们有的喜欢猫,有的喜欢狗,其中喜欢猫的一定不喜欢狗,喜欢狗的一定不喜欢猫.现在管理员要从动物园中移除一些动物,如果一个小孩喜欢的动物留了下来而不喜欢的动 ...
- HDU3829(KB10-J 二分图最大独立集)
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total ...
- BZOJ3175:[TJOI2013]攻击装置(二分图最大独立集)
Description 给定一个01矩阵,其中你可以在0的位置放置攻击装置.每一个攻击装置(x,y)都可以按照“日”字攻击其周围的 8个位置(x-1,y-2),(x-2,y-1),(x+1,y-2), ...
- [luoguP3355] 骑士共存问题(二分图最大独立集)
传送门 模型 二分图最大独立集,转化为二分图最大匹配,从而用最大流解决. 实现 首先把棋盘黑白染色,使相邻格子颜色不同. 把所有可用的黑色格子看做二分图X集合中顶点,可用的白色格子看做Y集合顶点. 建 ...
随机推荐
- mysql: 1045 access denied for user 'root'@'localhost' using password yes
原因是:root的密码错误了. 解决思路:关闭mysql服务,重新启动mysql服务,启动mysql的时候,指定不需要校验密码.然后登陆mysql,修改密码,退出.再重新启动mysql服务. 1.关闭 ...
- c++中的类的对象与类的指针
以上内容来自:http://wenku.baidu.com/link?url=haeRBhswlEcqddk48uW8YVMsdFNWsllimn_dzUYchb6G9NdT4pqgluCpnLQId ...
- Google Chrome input 设置 line-height 后光标变得和input一样高
Google Chrome input的height和line-height设置为相同的比默认高度高的值时,当input控件获得焦点并且没有输入内容时,input中的光标会占满整个input控件(如果 ...
- C# Socket编程(3)编码和解码
在网络通信中,很多情况下:比如说QQ聊天,通讯双方直接传递的都是字符信息.但是字符信息并不能够直接通过网络传输,这些字符集必须先转换成一个字节序列后才能够在网络中传输,于是这里就产生了编码和解码的概念 ...
- php中mysql数据库异步查询实现
问题 通常一个web应用的性能瓶颈在数据库.因为,通常情况下php中mysql查询是串行的.也就是说,如果指定两条sql语句时,第二条sql语句会等到第一条sql语句执行完毕再去执行.这个时候,如果执 ...
- VIm vi 使用 汇总
x 删除当前光标下的字符dw 删除光标之后的单词剩余部分.d$ 删除光标之后的该行剩余部分.dd 删除当前行. c 功能和d相同,区别在于完成删除操作后进入INSERT MODEcc 也是删除当前行, ...
- Hbase之Exception
[hadoop@master hbase-1.2.2]$ ./bin/hbase shell2016-08-25 13:53:56,898 WARN [main] util.NativeCodeLoa ...
- C++/C#中堆栈、对象内存模型、深浅拷贝、Array.Clone方法
转载自:http://blog.csdn.net/jarvischu/article/details/6425534 目录 1. C++/C#中对象内存模型................. ...
- 《javascript高级程序设计》第三章 Language Basics
3.1 语法syntax 3.1.1 区分大小写case-sensitivity 3.1.2 标识符identifiers 3.1.3 注释comments 3.1.4 严格模式strict mode ...
- postgresql异常快速定位
今天下午在使用.NET链接postgresql的时候报了“3D000”的错误,经过测试得知原来是web.config中的数据库配置问题. 在这里有个小情况需要注意,postgresql是不允许创建相同 ...