【POJ2771】【最大二分匹配】【反向图最小独立集】
2015-09-04 09:35
387 查看
Guardian of Decency
Description
Frank N. Stein is a very conservative high-school teacher. He wants to take some of his students on an excursion, but he is afraid that some of them might become couples. While you can never exclude this possibility, he has made some rules that he thinks indicates
a low probability two persons will become a couple:
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
The first line of the input consists of an integer T ≤ 100 giving the number of test cases. The first line of each test case consists of an integer N ≤ 500 giving the number of pupils. Next there will be one line for each pupil consisting of four space-separated
data items:
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
For each test case in the input there should be one line with an integer giving the maximum number of eligible pupils.
Sample Input
Sample Output
Source
Northwestern Europe 2005
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 5292 | Accepted: 2217 |
Frank N. Stein is a very conservative high-school teacher. He wants to take some of his students on an excursion, but he is afraid that some of them might become couples. While you can never exclude this possibility, he has made some rules that he thinks indicates
a low probability two persons will become a couple:
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
The first line of the input consists of an integer T ≤ 100 giving the number of test cases. The first line of each test case consists of an integer N ≤ 500 giving the number of pupils. Next there will be one line for each pupil consisting of four space-separated
data items:
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
For each test case in the input there should be one line with an integer giving the maximum number of eligible pupils.
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
Northwestern Europe 2005
#include <iostream> #include <cstring> #include <cmath> #include <queue> #include <stack> #include <list> #include <map> #include <set> #include <string> #include <cstdlib> #include <cstdio> #include <algorithm> using namespace std; const int N = 550; int g ; int used ; int uN,vN; int match ; bool dfs(int u) { for(int i=1;i<=vN;i++) { if(!used[i] && g[u][i]) { used[i] = true; if(match[i] == -1 || dfs(match[i])) { match[i] = u; return true; } } } return false; } int hungary() { int ret = 0; for(int i=1;i<=uN;i++) { memset(used,0,sizeof(used)); if(dfs(i)) ret++; } return ret; } int T; int n; struct Node { int age; char s1[4]; char s2[110]; char s3[110]; void input() { scanf("%d%s%s%s",&age,s1,s2,s3); } }node[550]; int main() { scanf("%d",&T); while(T --) { scanf("%d",&n); memset(g,0,sizeof(g)); memset(match,-1,sizeof(match)); for(int i=1;i<=n;i++) { node[i].input(); } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(abs(node[i].age-node[j].age) <= 40 && strcmp(node[i].s1,node[j].s1) !=0 && strcmp(node[i].s2,node[j].s2)==0 && strcmp(node[i].s3,node[j].s3) != 0) { // cout << i << " " << j << endl; g[i][j] = g[j][i] = 1; } } } uN = vN = n ; printf("%d\n",n-(hungary()) / 2); } return 0; }
相关文章推荐
- AspectJ报错:error at ::0 can't find referenced pointcut XXX
- HDOJ 4501 小明系列故事——买年货 DP
- jquery实现浮动在网页右下角的彩票开奖公告窗口代码
- Microsoft Natural Ergonomic 4000 zoom改键
- Android OkHttp文件上传与下载的进度监听扩展
- Android - Fragment+ViewPager结合使用
- 好用的PL/SQL Developer相关设置
- UILabel的文字与 label 的中间线对齐方式
- Remove Linked List Elements
- android 4.4 支持透明状态栏和透明导航栏
- PHP 中使用 SOAP
- Android Studio安装遇到的问题总结
- 1001. A+B Format (20)
- Android AutoCompleteTextView自动提示输入
- CentOS系统启动流程-2015090401
- 15.命令模式
- JavaScript中的逻辑运算的返回值(逻辑与&&,逻辑或||,逻辑非!)
- 【翻译自mos文章】怎么正确的使用SQLNET.ALLOWED_LOGON_VERSION参数
- stl 容器
- java模板类以及数组的简单使用