解决报告

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。

。。

#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

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

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

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

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. 编程算法 - 分割数 代码(C)

    分割数 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 有n个无差别的物品, 将它们划分成不超过m组, 求出划分方法数模M的余数. 比如: n= ...

  2. 谈论json - json经常使用的功能

    json经常使用的功能有JSON.parse().JSON.stringify(),供json对象和字符串之间的相互转换. 1.JSON.parse() 将 JavaScript 对象符号 (JSON ...

  3. android应用框架构建------AppManager

    体验一些Android应用程序开发的个人总结 当我们开发应用程序.经常有非常多非常多activity,在这一刻,我们需要一个activity堆栈,以帮助管理activity的finish和start. ...

  4. Android官方技术文档翻译——Gradle 插件用户指南(1-3)

    不知道是什么网络问题,上午一直发不了博客,其它页面基本正常,就是在写博客这里,每次打开都是响应超时.刚才用了VPN,顺便试了一下,竟然能够编辑.想是CDN之类的问题吧. 这次翻译的是Gradle 插件 ...

  5. php方法综述除去换行符(PHP_EOL使用变量)

    一个小包裹,事实上,不同的平台具有不同的实现.为什么要这样.它可以是一个世界是多样的. 最初unix与世界把它包/n取代,但windows为了体现自己的不同.要使用/r/n,更有意思的是,mac随着/ ...

  6. 七天来学习ASP.NET MVC (两)——ASP.NET MVC 数据传输

    通过第一天的学习之后,我们相信您已经对MVC有一些基本了解. 本节所讲的内容是在上节的基础之上.因此须要确保您是否掌握了上一节的内容. 本章的目标是在今天学习结束时利用最佳实践解决方式创建一个小型的M ...

  7. java得到clientIP地址和MAC住址

    最近的项目应该得到client的mac住址. 服务器移植centos制,arm建筑箱.client手机和移动设备.(其他方案也应该是一流的似的) 首先,要获得ip住址: 依据client的http请求 ...

  8. Oracle SQL 调优健康检查脚本

    Oracle SQL 调优健康检查脚本 我们关注数据库系统的性能,进行数据库调优的主要工作就是进行SQL的优化.良好的数据架构设计.配合应用系统中间件和写一手漂亮的SQL,是未来系统上线后不出现致命性 ...

  9. 十依据一个有用的算法来找到最小(最大)的k的数量-线性搜索算法

    例如:进入1.2.3,4,5,6.7.8此8数字,最小的4图的1,2,3,4. 思路1:最easy想到的方法:先对这个序列从小到大排序.然后输出前面的最小的k个数就可以.假设选择高速排序法来进行排序, ...

  10. atittit.表单验证性质的原则和实施,以及选择和定义自己的兼容easyui dsl窗体身份验证规则

    atittit.表单验证性质的原则和实施,以及选择和定义自己的兼容easyui dsl规则的表单验证 1. 需求,表单验证须要弹框式,但眼下easyui ms绑定死了tooltip式样 1 2. 表单 ...