POJ2771_Guardian of Decency(二分图/最大独立集=N-最大匹配)
2015-07-18 20:50
369 查看
解决报告
/article/2643375.html
题目传送门
题意:
看到题目我就笑了。。,
老师觉得这种两个学生不是一对:
身高相差40以上(年龄都不是距离了,身高又算什么)
不同性别(sad。。,就不同意基友存在呀。,,谁的肥皂掉了。,。)
喜欢不一样的歌曲类型(你总不能要求两人整天听小苹果吧,,,,,,你是我的小丫小苹果,,,,,,)
喜欢一样的运动( they are likely to be fans of different teams and that would result in fighting......这是什么理由。喜欢同个不同球队还会打起来)
问最多的不在一起的有多少人
思路:
不在一起代表独立于相爱关系的。也就是求最大独立集,集合里面随意两个人都不相爱
最大独立集=结点数-最大匹配
ps不知道是不是写挫了,重写才过。sad。
。。
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
/article/2643375.html
题目传送门
题意:
看到题目我就笑了。。,
老师觉得这种两个学生不是一对:
身高相差40以上(年龄都不是距离了,身高又算什么)
不同性别(sad。。,就不同意基友存在呀。,,谁的肥皂掉了。,。)
喜欢不一样的歌曲类型(你总不能要求两人整天听小苹果吧,,,,,,你是我的小丫小苹果,,,,,,)
喜欢一样的运动( they are likely to be fans of different teams and that would result in fighting......这是什么理由。喜欢同个不同球队还会打起来)
问最多的不在一起的有多少人
思路:
不在一起代表独立于相爱关系的。也就是求最大独立集,集合里面随意两个人都不相爱
最大独立集=结点数-最大匹配
ps不知道是不是写挫了,重写才过。sad。
。。
#include <cmath> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct node { int h; char sex; char mus[110]; char spo[110]; }M[510],F[510]; int n,m,f,mmap[550][550],pre[550],vis[550]; int pd(int i,int j) { if( abs(M[i].h - F[j].h) > 40 ) return 0; if( strcmp(M[i].mus,F[j].mus) ) return 0; if( strcmp(M[i].spo,F[j].spo) == 0 ) return 0; return 1; } int dfs(int x) { for(int i=m+1;i<=m+f;i++){ if(!vis[i]&&mmap[x][i]){ vis[i]=1; if(pre[i]==-1||dfs(pre[i])){ pre[i]=x; return 1; } } } return 0; } int main() { int i,j,t,h; char str[100]; scanf("%d",&t); while(t--){ scanf("%d",&n); m=f=1; memset(mmap,0,sizeof(mmap)); memset(pre,-1,sizeof(pre)); memset(M,0,sizeof(M)); memset(F,0,sizeof(F)); for(i=1;i<=n;i++){ scanf("%d%s",&h,str); if(str[0]=='M'){ scanf("%s%s",M[m].mus,M[m].spo); M[m].h=h; M[m++].sex='M'; } else { scanf("%s%s",F[f].mus,F[f].spo); F[f].h=h; F[f++].sex='F'; } } for(i=1;i<=m;i++){ for(j=1;j<=f;j++){ if(pd(i,j)) mmap[i][m+j]=1; } } int ans=0; for(i=1;i<=m;i++){ memset(vis,0,sizeof(vis)); ans+=dfs(i); } printf("%d\n",n-ans); } }
Guardian of Decency
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 4876 | Accepted: 2056 |
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
相关文章推荐
- MYSQL操作的一些知识点,持续更新中····
- Java Inventory代码解释
- IntelliJ IDEA 13 破解安装(JRebel 5.6.3a皴)
- Jsoup 抓取和数据页 认识HTTP头
- hdu 1561 树形dp
- 黑马程序员——Java基础---基础语法
- 括号配对问题
- 从外部导入jar包的三种方式
- Java窗体
- java读取properties文件
- 进程间通讯(一) --- 信号
- C# WinForm 关闭登陆窗体,打开主窗体的实现
- [cocos2dx]可视元素——CCLayer图层类
- 标识符
- 数据分析:中国高校更名历史 Python
- [Leetcode] Merge Sorted Array
- Struts1 和 Struts2的区别(11点)
- 数据结构学习总结(四)队列和栈
- eclipse中使用快捷键ctrl+shift+F无法格式化代码的问题解决方法
- iOS开发:快速集成支付宝快捷支付