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 ...
随机推荐
- C++介绍与入门学习
C++是C语言的继承,它既可以进行C语言的过程化程序设计,又可以进行以抽象数据类型为特点的基于对象的程序设计,还可以进行以继承和多态为特点的面向对象的程序设计.C++擅长面向对象程序设计的同时,还可以 ...
- c 最简单的链表
#include <stdio.h> struct node { int data; struct node *next; //指向本身的指针 }; // main() { struct ...
- H2数据库入门使用
H2数据库入门使用 学习了: https://www.cnblogs.com/xdp-gacl/p/4171024.html http://www.cnblogs.com/xdp-gacl/p/417 ...
- [Python + Unit Testing] Write Your First Python Unit Test with pytest
In this lesson you will create a new project with a virtual environment and write your first unit te ...
- CentOS 安装SVNclient
1.检查是已经安装了svn: # rpm -qa subversion subversion-1.7.14-6.el7.x86_64 卸载旧版本号的svn: # yum remove subversi ...
- 343D/Codeforces Round #200 (Div. 1) D. Water Tree dfs序+数据结构
D. Water Tree Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each ...
- linux使用windows中编辑的文件,格式问题
参考:https://blog.csdn.net/yongan1006/article/details/8142527 运行脚本时出现了这样一个错误,打开之后并没有找到所谓的^M,查了之后才知道原来是 ...
- scanf正则表达式
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> void main() { ] = ...
- Kettle学习系列之Kettle的起源
不多说,直接上干货! Kettle起源于十年以前,本世纪初.当时啊,ETL工具千姿百态,比较流行的工具有50个左右,ETL框架数量比工具还要多些. 根据这些工具的各自起源和功能可以分为以下4种类型,如 ...
- 批量kill 某个用户session
SELECT 'alter system kill session '''||SID || ',' || SERIAL#||''';' FROM V$SESSION where username ...