解决报告

http://blog.csdn.net/juncoder/article/details/38159017

题目传送门

题意:

看到题目我就笑了。。,

老师觉得这种两个学生不是一对:

身高相差40以上(年龄都不是距离了,身高又算什么)

不同性别(sad。。,就不同意基友存在呀。,,谁的肥皂掉了。,。)

喜欢不一样的歌曲类型(你总不能要求两人整天听小苹果吧,,,,,,你是我的小丫小苹果,,,,,,)

喜欢一样的运动( they are likely to be fans of different teams and that would result in fighting......这是什么理由。喜欢同个不同球队还会打起来)

问最多的不在一起的有多少人

思路:

不在一起代表独立于相爱关系的。也就是求最大独立集,集合里面随意两个人都不相爱

最大独立集=结点数-最大匹配

ps不知道是不是写挫了,重写才过。sad。

。。

  1. #include <cmath>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. using namespace std;
  6. struct node
  7. {
  8. int h;
  9. char sex;
  10. char mus[110];
  11. char spo[110];
  12. }M[510],F[510];
  13. int n,m,f,mmap[550][550],pre[550],vis[550];
  14. int pd(int i,int j)
  15. {
  16. if( abs(M[i].h - F[j].h) > 40 )
  17. return 0;
  18. if( strcmp(M[i].mus,F[j].mus) )
  19. return 0;
  20. if( strcmp(M[i].spo,F[j].spo) == 0 )
  21. return 0;
  22. return 1;
  23. }
  24. int dfs(int x)
  25. {
  26. for(int i=m+1;i<=m+f;i++){
  27. if(!vis[i]&&mmap[x][i]){
  28. vis[i]=1;
  29. if(pre[i]==-1||dfs(pre[i])){
  30. pre[i]=x;
  31. return 1;
  32. }
  33. }
  34. }
  35. return 0;
  36. }
  37. int main()
  38. {
  39. int i,j,t,h;
  40. char str[100];
  41. scanf("%d",&t);
  42. while(t--){
  43. scanf("%d",&n);
  44. m=f=1;
  45. memset(mmap,0,sizeof(mmap));
  46. memset(pre,-1,sizeof(pre));
  47. memset(M,0,sizeof(M));
  48. memset(F,0,sizeof(F));
  49. for(i=1;i<=n;i++){
  50. scanf("%d%s",&h,str);
  51. if(str[0]=='M'){
  52. scanf("%s%s",M[m].mus,M[m].spo);
  53. M[m].h=h;
  54. M[m++].sex='M';
  55. }
  56. else {
  57. scanf("%s%s",F[f].mus,F[f].spo);
  58. F[f].h=h;
  59. F[f++].sex='F';
  60. }
  61. }
  62. for(i=1;i<=m;i++){
  63. for(j=1;j<=f;j++){
  64. if(pd(i,j))
  65. mmap[i][m+j]=1;
  66. }
  67. }
  68. int ans=0;
  69. for(i=1;i<=m;i++){
  70. memset(vis,0,sizeof(vis));
  71. ans+=dfs(i);
  72. }
  73. printf("%d\n",n-ans);
  74. }
  75. }
Guardian of Decency
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 4876   Accepted: 2056

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

  1. 2
  2. 4
  3. 35 M classicism programming
  4. 0 M baroque skiing
  5. 43 M baroque chess
  6. 30 F baroque soccer
  7. 8
  8. 27 M romance programming
  9. 194 F baroque programming
  10. 67 M baroque ping-pong
  11. 51 M classicism programming
  12. 80 M classicism Paintball
  13. 35 M baroque ping-pong
  14. 39 F romance ping-pong
  15. 110 M romance Paintball

Sample Output

  1. 3
  2. 7

版权声明:本文博客原创文章。博客,未经同意,不得转载。

POJ2771_Guardian of Decency(二分图/最大独立集=N-最大匹配)的更多相关文章

  1. 【Codevs1922】骑士共存问题(最小割,二分图最大独立集转最大匹配)

    题意: 在一个n*n个方格的国际象棋棋盘上,马(骑士)可以攻击的棋盘方格如图所示.棋盘上某些方格设置了障碍,骑士不得进入. 对于给定的n*n个方格的国际象棋棋盘和障碍标志,计算棋盘上最多可以放置多少个 ...

  2. UVA-12083 Guardian of Decency 二分图 最大独立集

    题目链接:https://cn.vjudge.net/problem/UVA-12083 题意 学校组织去郊游,选择最多人数,使得任意两个人之间不能谈恋爱 不恋爱条件是高差大于40.同性.喜欢的音乐风 ...

  3. 长脖子鹿放置【洛谷P5030】二分图最大独立集变形题

    题目背景 众周所知,在西洋棋中,我们有城堡.骑士.皇后.主教和长脖子鹿. 题目描述 如图所示,西洋棋的“长脖子鹿”,类似于中国象棋的马,但按照“目”字攻击,且没有中国象棋“别马腿”的规则.(因为长脖子 ...

  4. HDU 3829 - Cat VS Dog (二分图最大独立集)

    题意:动物园有n只猫和m条狗,现在有p个小孩,他们有的喜欢猫,有的喜欢狗,其中喜欢猫的一定不喜欢狗,喜欢狗的一定不喜欢猫.现在管理员要从动物园中移除一些动物,如果一个小孩喜欢的动物留了下来而不喜欢的动 ...

  5. HDU3829(KB10-J 二分图最大独立集)

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total ...

  6. bzoj 1143 二分图最大独立集

    我们可以将一个点拆成两个点x,y,那么如果存在一条i->j的路径,我们就连接xi,yj,那么答案就是n-最大匹配数. 因为i->j所以对于i与j只能选一个,那么我们只需要求出来二分图的最大 ...

  7. [luoguP3355] 骑士共存问题(二分图最大独立集)

    传送门 模型 二分图最大独立集,转化为二分图最大匹配,从而用最大流解决. 实现 首先把棋盘黑白染色,使相邻格子颜色不同. 把所有可用的黑色格子看做二分图X集合中顶点,可用的白色格子看做Y集合顶点. 建 ...

  8. 洛谷 - P5030 - 长脖子鹿放置 - 二分图最大独立集

    https://www.luogu.org/problemnew/show/P5030 写的第一道黑色题,图建对了. 隐约觉得互相攻击要连边,规定从奇数行流向偶数行. 二分图最大独立集=二分图顶点总数 ...

  9. TopCoder12808 「SRM594Medium」FoxAndGo3 二分图最大独立集

    问题描述 一个 \(N \times N\) 围棋棋盘,任意两个白子不相邻,你要加入若干个黑子并提出白子,最大化空格数目. submit 题解 显然最终棋盘的局面不能够一个白子和它周围的空格都是空的, ...

随机推荐

  1. mybatis至mysql插入一个逗号包含值误差

    mybatis至mysql插入形如"11,22,33"当误差.我使用了错误的原因是美元符号镶嵌sql.正确的做法是使用#  有时间去看看mybatis的$和#差异. 版权声明:本文 ...

  2. java通讯录

    )设一个通信录由以下几项数据信息构成: 数据项               类型 姓名                  字符串 地址                  字符串 邮政编码        ...

  3. Codeforces Round #234 (Div. 2) B. Inna and New Matrix of Candies

    B. Inna and New Matrix of Candies time limit per test 1 second memory limit per test 256 megabytes i ...

  4. nyoj 7 街区最短路径问题 【数学】

    找出横纵坐标的中位数,怎么找:先对x排序找x的中位数x0,再对y排序找y的中位数y0:最后统计各点到中位数点(x0, y0)的总距离: 街区最短路径问题 时间限制:3000 ms  |  内存限制:6 ...

  5. [原创].NET 业务框架开发实战之六 DAL的重构

    原文:[原创].NET 业务框架开发实战之六 DAL的重构 .NET 业务框架开发实战之六 DAL的重构 前言:其实这个系列还是之前的".NET 分布式架构开发实战 ",之所以改了 ...

  6. bat(批处理文件)初步 第一篇 基本符号

    近期我使用的一款软件中须要大量的环境变量设置,而我又不想讲这些变量都加入到系统的环境变量中,一方面是由于有一些同名的库文件的版本号却不一样,都 写在系统环境中会相互干扰:还有一方面则是大部分的路径仅仅 ...

  7. javascript事件和事件处理

    于js期间事件处理被分成三个步骤: 1.发生事件 2.启动事件处理程序 3.事件处理程序做出反应 事件处理程序的调用 1.在javascript中 在javascript中调用事件处理程序,首先要获得 ...

  8. JMS ActiveMQ研究文档

    1. 背景 当前,CORBA.DCOM.RMI等RPC中间件技术已广泛应用于各个领域.但是面对规模和复杂度都越来越高的分布式系统,这些技术也显示出其局限性:(1)同步通信:客户发出调用后,必须等待服务 ...

  9. 照片教你eclipse通过使用gradle 打包Android

    gradle其他优点不说,在android当应用程序公布.假设你要算一些渠道,gradle 在节目包装散装优势:下面给大家介绍的图形 按eclipse当出口 选择Android:例如下面的附图 一步一 ...

  10. hdu 4912 Paths on the tree(树链拆分+贪婪)

    题目链接:hdu 4912 Paths on the tree 题目大意:给定一棵树,和若干个通道.要求尽量选出多的通道,而且两两通道不想交. 解题思路:用树链剖分求LCA,然后依据通道两端节点的LC ...