POJ 2771 Guardian of Decency 【最大独立集】
传送门:http://poj.org/problem?id=2771
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 6456 | Accepted: 2668 |
Description
- 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
题意概括:
有 N 个学生,依次给出他们的身高、性别、喜欢音乐的类型、喜欢的运动。
老师给出了 四条 不可能成为亲密关系的条件。老师想带尽可能多的学生,但是有不想他们发展成为亲密恋人(两两至少满足一条上述的条件)。
问最多能带多少学生?
解题思路:
我们把条件反过来建图,即有可能成为亲密关系的连边。
那么就转换为求他们的最大独立集了。
AC code:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN = ;
struct date
{
int h;
char mf[], music[], spo[];
}pp[MAXN]; struct Edge
{
int v, nxt;
}edge[MAXN*MAXN]; int head[MAXN],cnt;
int linker[MAXN];
bool used[MAXN];
int N; void init()
{
memset(head, -, sizeof(head));
memset(linker, -, sizeof(linker));
memset(edge, , sizeof(edge));
cnt = ;
} void add(int from, int to)
{
edge[cnt].v = to;
edge[cnt].nxt = head[from];
head[from] = cnt++;
} bool Find(int x)
{
int v;
for(int i = head[x]; i != -; i = edge[i].nxt){
v = edge[i].v;
if(!used[v]){
used[v] = true;
if(linker[v] == - || Find(linker[v])){
linker[v] = x;
return true;
}
}
}
return false;
} bool chk(date a, date b)
{
if(abs(a.h-b.h) <= ){
if(a.mf[] != b.mf[]){
if(strcmp(a.music, b.music) == ){
if(strcmp(a.spo, b.spo) != ){
return true;
}
}
}
}
return false;
} int main()
{
int T_case;
scanf("%d", &T_case);
while(T_case--){
init();
scanf("%d", &N);
for(int i = ; i <= N; i++){
scanf("%d %s %s %s", &pp[i].h, &pp[i].mf, &pp[i].music, &pp[i].spo);
for(int j = ; j < i; j++){
if(chk(pp[i], pp[j])){
add(i, j);
add(j, i);
}
}
}
int ans = ;
for(int i = ; i <= N; i++){
memset(used, , sizeof(used));
if(Find(i)) ans++;
}
printf("%d\n", N-ans/);
}
return ;
}
POJ 2771 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 (二分图最大点独立集)
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 题目意思:有一个保守的老师要带他的学生来一次短途旅行,但是他又害怕有些人会变成情侣关系,于是就想出了一个方法: 1.身高差距 ...
- POJ 2771 Guardian of Decency
http://poj.org/problem?id=2771 题意: 一个老师想带几个同学出去,但是他怕他们会谈恋爱,所以带出去的同学两两之间必须满足如下条件之一: ①身高差大于40 ②同性 ③喜欢 ...
- 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个条件都不满足才能成为一对),求可能的最多的单身人数. 思路:把男女分为两部分,接下来就是二分图的匹配问题.把能成为一对的之间连边,然后求出最 ...
- POJ——T2271 Guardian of Decency
http://poj.org/problem?id=2771 Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5932 A ...
随机推荐
- 设计模式学习总结(六)原型模式(Prototype)
原型模式即通过对象拷贝的方式来实现对同类对象的生成的一种设计模式! 浅复制:对于值类型,则直接复制该值,对于引用类型的字段则是对其引用的复制,如果原引用与现引用只要有一个的值发生变化,则都会造成两者值 ...
- ZABBIX 监控基本报警故障
CPU触发器: 1)Processor load is too high on {HOST.NAME} {HOST.NAME}上处理器负载太高 触发器表达式:{Zabbix server:system ...
- 【转】python平台libsvm安装
来源:http://blog.csdn.net/prom1201/article/details/51382358 网上有很多麻烦的在win64机器上安装libsvm的步骤,实际上只要在下面网站找到l ...
- 深度学习(五)基于tensorflow实现简单卷积神经网络Lenet5
原文作者:aircraft 原文地址:https://www.cnblogs.com/DOMLX/p/8954892.html 参考博客:https://blog.csdn.net/u01287127 ...
- nyoj 409——郁闷的C小加(三)——————【中缀式化前缀后缀并求值】
郁闷的C小加(三) 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 聪明的你帮助C小加解决了中缀表达式到后缀表达式的转换(详情请参考“郁闷的C小加(一)”),C小加很 ...
- swpuctf-web部分学习总结
1.用优惠码 买个 X ? (1)第一步: 这道题第一步主要知道利用php的随机种子数泄露以后就可以利用该种子数来预测序列,而在题目中会返回15位的优惠码,但是必须要24位的优惠码,因此要根据15位的 ...
- [转].NET Core之Entity Framework Core 你如何创建 DbContext
本文转自:http://www.cnblogs.com/tdws/p/5874212.html 本文版权归博客园和作者吴双共同所有,欢迎转载,转载和爬虫请注明博客园蜗牛原文地址 http://www. ...
- c#.net常见字符串处理方法
1.字符串比较 字符串.ComparTo(目标字符串) "a".ComparTo("b"); 2.查找子串 字符串.IndexOf(子串,查找其实位置) ; 字 ...
- redis的有序集合(Sorted Sets)数据类型
和Sets相比,Sorted Sets增加了一个权重参数score,使得集合中的元素能够按score进行有序排列,比如一个存储全班同学成绩的Sorted Sets,其集合value可以是同学的学号,而 ...
- Jquery系列:checkbox 获取值、选中、设置值、事件监听等操作
<div id="divId" class="divTable"> <div class="tableBody"> ...