UVA-12083 Guardian of Decency 二分图 最大独立集
题目链接:https://cn.vjudge.net/problem/UVA-12083
题意
学校组织去郊游,选择最多人数,使得任意两个人之间不能谈恋爱
不恋爱条件是高差大于40、同性、喜欢的音乐风格不同、喜欢的运动相同中的任意一个
思路
二分图最大独立集,集合内任两节点间没有边
最大独立集节点数=总结点数-最大匹配
模版题咯
提交过程
CE1 | 选错语言 |
CE2 | string头文件忘写 |
AC |
代码
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
const int maxn=500+20;
struct Person{
int hei;
bool male;
string music, sport;
}person[2][maxn];
bool G[maxn][maxn], vis[maxn];
int match[maxn], n, m;
bool dfs(int u){
for (int i=0; i<m; i++) if (!vis[i] && G[u][i]){
vis[i]=true;
if (match[i]==-1 || dfs(match[i])){
match[i]=u;
return true;
}
}return false;
}
int solve(void){
int ans=0;
memset(match, -1, sizeof(match));
for (int i=0; i<n; i++){
memset(vis, false, sizeof(vis));
if (dfs(i)) ans++;
}return ans;
}
int main(void){
int T, size;
char music[100], sport[100], sex[5];
int hei;
scanf("%d", &T);
while (T--){
n=m=0;
scanf("%d", &size);
for (int i=0; i<size; i++){
scanf("%d%s%s%s", &hei, sex, music, sport);
if (sex[0]=='M') person[0][n++]=Person{hei, 1, string(music), string(sport)};
else person[1][m++]=Person{hei, 0, string(music), string(sport)};
}
memset(G, false, sizeof(G));
for (int i=0; i<n; i++)
for (int j=0; j<m; j++){
Person &male=person[0][i], &female=person[1][j];
if (abs(male.hei-female.hei)<=40 && male.music==female.music && male.sport!=female.sport)
G[i][j]=true;
}
printf("%d\n", n+m-solve());
}
return 0;
}
Time | Memory | Length | Lang | Submitted |
---|---|---|---|---|
40ms | 1265 | C++11 5.3.0 | 2018-07-26 14:06:14 |
UVA-12083 Guardian of Decency 二分图 最大独立集的更多相关文章
- uva 12083 Guardian of Decency (二分图匹配)
uva 12083 Guardian of Decency Description Frank N. Stein is a very conservative high-school teacher. ...
- UVA - 12083 Guardian of Decency (二分匹配)
题意:有N个人,已知身高.性别.音乐.运动.要求选出尽可能多的人,使这些人两两之间至少满足下列四个条件之一. 1.身高差>40 2.性别相同 3.音乐不同 4.运动相同 分析: 1.很显然 ...
- POJ2771_Guardian of Decency(二分图/最大独立集=N-最大匹配)
解决报告 http://blog.csdn.net/juncoder/article/details/38159017 题目传送门 题意: 看到题目我就笑了.., 老师觉得这种两个学生不是一对: 身高 ...
- POJ 2771 Guardian of Decency 【最大独立集】
传送门:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Tot ...
- UVAlive3415 Guardian of Decency(最大独立集)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34831 [思路] 二分图的最大独立集. 即在二分图中选取最多的点, ...
- UVALive-3415 Guardian of Decency (最大独立集)
题目大意:一个老师要带一些学生去春游,但是要带的学生中任意两个人都满足下面四个条件中的至少一个:1.性别相同:2.身高差大与40公分:3.最喜欢的音乐类型不同:4.最喜欢的体育运动相同.问老师最多能带 ...
- POJ 2771 Guardian of Decency(最大独立集数=顶点数-最大匹配数)
题目链接: http://poj.org/problem?id=2771 Description Frank N. Stein is a very conservative high-school t ...
- Guardian of Decency(二分图)
Guardian of Decency Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submi ...
- Guardian of Decency UVALive - 3415 最大独立集=结点数-最大匹配数 老师带大学生旅游
/** 题目:Guardian of Decency UVALive - 3415 最大独立集=结点数-最大匹配数 老师带大学生旅游 链接:https://vjudge.net/problem/UVA ...
随机推荐
- nsrunloop与模式
scrollview的模式切换:退出原来的模式使用新模式. 2018-04-18 18:16:41.208113+0800 CEMonitor[5014:410604] kCFRunLoopDefau ...
- Prototype-based programming
Prototype-based programming is a style of object-oriented programming in which behaviour reuse (know ...
- Kattis -I Can Guess the Data Structure!
I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x1 ...
- python的基础及练习
1.变量变是指变化,量是指反映某种状态例:level =1 或 2 username = ‘xuanxuan’password = ‘123’python里的“=”是赋值的意思,并不是真的等于 变量有 ...
- Vue -- 只弹一次的弹框
核心代码是 getCookie()部分,控制弹框的显示隐藏则在 created()中. <template> <div v-if="isShow"> < ...
- 洛谷 P3133 [USACO16JAN]无线电联系Radio Contact
P3133 [USACO16JAN]无线电联系Radio Contact 题目描述 Farmer John has lost his favorite cow bell, and Bessie the ...
- 面试书上一些题目的整理:O(n)复杂度排序年龄 & 青蛙跳台阶
可以按照年龄的个数,设置99个桶,然后桶内处理. 青蛙跳台阶,每次1阶或者2阶,就是fib数 如果每次1到n阶,那么归纳法可得,是2^(n-1) 另外1*2 覆盖 2*n个矩阵的问题,仍然是Fib数. ...
- Qt程序打包成exe可执行文件
很多Qt爱好者想发布自己的Qt软件,但却发现在其他没有安装Qt SDK的机器上无法运行,这就是本文想要说明的问题.现在网上大部分软件都要发布自己开发的应用程序,都会打包到exe文件中,待安装完exe文 ...
- UVA 11294 - Wedding(Two-Set)
UVA 11294 - Wedding 题目链接 题意:有n对夫妻,0号是公主.如今有一些通奸关系(男男,女女也是可能的)然后要求人分配在两側.夫妻不能坐同一側.而且公主对面一側不能有两个同奸的人,问 ...
- 计算机网络 4.网络层与IP协议
网络中的每一台主机和路由器都有一个网络层部分.而路由器中也没有网络层以上的层次.网络层是协议栈中最复杂的层次. 转发forwarding:当一个分组到达某路由器的输入链路时.该路由器将分组移动到适当的 ...