POJ——T2271 Guardian of Decency
http://poj.org/problem?id=2771
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 5932 | Accepted: 2463 |
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
- 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 <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio> using namespace std; const int N(+);
int t,n,h,ans; int sumb,sumg;
struct Node
{
int heigh;
char music[],sport[];
}boy[N],girl[N]; int head[N],sumedge;
struct Edge
{
int u,v,next;
Edge(int u=,int v=,int next=):
u(u),v(v),next(next){}
}edge[N*N];
void ins(int u,int v)
{
edge[++sumedge]=Edge(u,v,head[u]);
head[u]=sumedge;
} int vis[N],match[N];
bool DFS(int x)
{
for(int i=head[x];i;i=edge[i].next)
{
int v=edge[i].v;
if(vis[v]) continue;
vis[v]=;
if(!match[v]||DFS(match[v]))
{
match[v]=x;
return true;
}
}
return false;
} void init()
{
ans=sumedge=sumb=sumg=;
memset(boy,,sizeof(boy));
memset(girl,,sizeof(girl));
memset(head,,sizeof(head));
memset(match,,sizeof(match));
scanf("%d",&n);
} int main()
{
scanf("%d",&t);
for(;t--;)
{
init();char xb;
for(int h,i=;i<=n;i++)
{
scanf("%d",&h);cin>>xb;
if(xb=='F') boy[++sumb].heigh=h,scanf("%s%s",boy[sumb].music,boy[sumb].sport);
else girl[++sumg].heigh=h,scanf("%s%s",girl[sumg].music,girl[sumg].sport);
}
for(int i=;i<=sumb;i++)
for(int j=;j<=sumg;j++)
if(abs(boy[i].heigh-girl[j].heigh)<=&&!strcmp(boy[i].music,girl[j].music)&&strcmp(boy[i].sport,girl[j].sport))
ins(i,j);
for(int i=;i<=sumb;i++)
{
memset(vis,,sizeof(vis));
if(DFS(i)) ans++;
}
printf("%d\n",n-ans);
}
return ;
}
POJ——T2271 Guardian of Decency的更多相关文章
- poj——2771 Guardian of Decency
poj——2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5916 ...
- POJ 2771 Guardian of Decency 【最大独立集】
传送门:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Tot ...
- POJ 2771 Guardian of Decency (二分图最大点独立集)
Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6133 Accepted: 25 ...
- POJ 2771 Guardian of Decency(最大独立集数=顶点数-最大匹配数)
题目链接: http://poj.org/problem?id=2771 Description Frank N. Stein is a very conservative high-school t ...
- POJ 2771 Guardian of Decency
http://poj.org/problem?id=2771 题意: 一个老师想带几个同学出去,但是他怕他们会谈恋爱,所以带出去的同学两两之间必须满足如下条件之一: ①身高差大于40 ②同性 ③喜欢 ...
- poj 2771 Guardian of Decency 解题报告
题目链接:http://poj.org/problem?id=2771 题目意思:有一个保守的老师要带他的学生来一次短途旅行,但是他又害怕有些人会变成情侣关系,于是就想出了一个方法: 1.身高差距 ...
- POJ 2771 Guardian of Decency(求最大点独立集)
该题反过来想:将所有可能发生恋爱关系的男女配对,那么可以带出去的人数应该等于这个二分图的最大独立集 先要做一下预处理,把不符合要求的双方先求出来, company[i][j]表示i.j四个标准都不符合 ...
- UVA 12083 POJ 2771 Guardian of Decency
/* http://acm.hust.edu.cn/vjudge/contest/view.action?cid=71805#problem/C */ 性质: [1]二分图最大点独立数=顶点数-二分图 ...
- poj 2771 Guardian of Decency(最大独立数)
题意:人与人之间满足4个条件之一即不能成为一对(也就说这4个条件都不满足才能成为一对),求可能的最多的单身人数. 思路:把男女分为两部分,接下来就是二分图的匹配问题.把能成为一对的之间连边,然后求出最 ...
随机推荐
- vue.2.0-自定义全局组件
App.vue <template> <div id="app"> <h3>welcome vue-loading</h3> < ...
- Lesson 2 Building your first web page: Part 2
Tag Diagram You may have noticed that HTML tags come in pairs; HTML has both an opening tag (<tag ...
- 20.发送http请求服务 ($http)
转自:https://www.cnblogs.com/best/tag/Angular/ 服务从代码直接与服务器进行交互,底层是通过实现,与中http服务从AngularJS代码直接与Web服务器进行 ...
- HDU 5370 Tree Maker
一个显然的结论是,一棵n个结点的二叉树的形态数,是Catalan数第n项.
- Spring Security Java Config Preview--官方
原文地址:[1]https://spring.io/blog/2013/07/02/spring-security-java-config-preview-introduction/ [2]https ...
- 安装SQL2008后需要打开的端口为 1433,4630
- UVa 10101 - Bangla Numbers
题目:将数字数转化成数字加单词的表示形式输出. 分析:数论.简单题.直接分成两部分除10000000的商和余数,分别输出就可以. 说明:注意输入为数字0的情况,还有long long类型防止溢出. # ...
- Android ScrollView滚动实现大众点评、网易云音乐评论悬停效果
今天听着网易云音乐,写着代码,真是爽翻了. http://blog.csdn.net/linshijun33/article/details/47910833 网易云音乐这个产品亮点应该在评论这一模块 ...
- vue2留言板
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- elasticsearch index 之 engine
elasticsearch对于索引中的数据操作如读写get等接口都封装在engine中,同时engine还封装了索引的读写控制,如流量.错误处理等.engine是离lucene最近的一部分. engi ...