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 ...
随机推荐
- VSCode Debug模式下各图标 含义
按钮1:运行/继续 F5,真正的一步一步运行 按钮2:单步跳过(又叫逐过程) F10,按语句单步执行.当有函数时,不会进入函数. 按钮3:单步调试(又叫逐语句) F11:当有函数时,点击这个按钮,会进 ...
- 使用css选择器来定位元素
public void CSS(){ driver.get(Constant.baidu_url); //绝对路径 // driver.findElement(By.cssSelector(" ...
- TF基础2
1.常用API 1.图,操作和张量 tf.Graph,tf.Operation,tf.Tensor 2.可视化 TensorBoard 3.变量作用域 在TF中有两个作用域(scope),一个是nam ...
- NOI 2015 寿司晚宴 (状压DP+分组背包)
题目大意:两个人从2~n中随意取几个数(不取也算作一种方案),被一个人取过的数不能被另一个人再取.两个人合法的取法是,其中一个人取的任何数必须与另一个人取的每一个数都互质,求所有合法的方案数 (数据范 ...
- Vue系列(一):简介、起步、常用指令、事件和属性、模板、过滤器
一. Vue.js简介 1. Vue.js是什么 Vue.js也称为Vue,读音/vju:/,类似view,错误读音v-u-e 是一个轻量级MVVM(Model-View-ViewModel)框架,和 ...
- 新手学python-Day2-变量和循环判断
第二天作业: 初探三级菜单,凭现有知识,注意变量可以不声明,但要提前赋值! 此处shuru = '' 可以不写,因为第7行被赋值了,如果只调用shuru不赋值就会报错 shuru = '' sheng ...
- IE6 浏览器常见兼容问题 共23个
1.<!DOCTYPE HTML>文档类型的声明. 产生条件:IE6浏览器,当我们没有书写这个文档声明的时候,会触发IE6浏览器的怪异解析现象: 解决办法:书写文档声明. 2.不同浏览器当 ...
- dubbo Failed to check the status of the service com.user.service.UserService. No provider available for the service
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'u ...
- python多线程编程代码
参考了这篇文章,写的挺好的. http://blog.csdn.net/abcjennifer/article/details/49474897 import time import threadin ...
- HDU 4035
dp求期望的题. 设 E[i]表示在结点i处,要走出迷宫所要走的边数的期望.E[1]即为所求. 叶子结点: E[i] = ki*E[1] + ei*0 + (1-ki-ei)*(E[father[i] ...