UVALive-3415 Guardian of Decency (最大独立集)
题目大意:一个老师要带一些学生去春游,但是要带的学生中任意两个人都满足下面四个条件中的至少一个:1、性别相同;2、身高差大与40公分;3、最喜欢的音乐类型不同;4、最喜欢的体育运动相同。问老师最多能带多少个学生?
题目分析:最大独立集问题。最大独立集+最小覆盖集=全集。将学生视为节点,对于任意两个不满足上述四个条件中的学生,连一条有向边。这就意味着一条边的两个端点至少有一个不能去春游,这与一条边中至少有一个去春游恰好互补,后者正是最小覆盖问题。
代码如下:
# include<iostream>
# include<cstdio>
# include<string>
# include<vector>
# include<cstring>
# include<algorithm>
using namespace std;
# define REP(i,s,n) for(int i=s;i<n;++i)
# define CL(a,b) memset(a,b,sizeof(a))
# define CLL(a,b,n) fill(a,a+n,b) const int N=505;
struct student
{
int high;
char sex;
string music,PE;
};
student stu[N];
int n,vis[N],link[N];
vector<int>G[N]; bool ok(int i,int j)
{
if(stu[i].sex==stu[j].sex) return false;
if(stu[i].PE==stu[j].PE) return false;
if(abs(stu[i].high-stu[j].high)>40) return false;
if(stu[i].music!=stu[j].music) return false;
return true;
} bool dfs(int x)
{
REP(i,0,G[x].size()){
int y=G[x][i];
if(vis[y]) continue;
vis[y]=1;
if(link[y]==-1||dfs(link[y])){
link[y]=x;
return true;
}
}
return false;
} int match()
{
int res=0;
CL(link,-1);
REP(i,1,n+1){
CL(vis,0);
if(dfs(i)) ++res;
}
return res;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
REP(i,1,n+1) G[i].clear();
REP(i,1,n+1) cin>>stu[i].high>>stu[i].sex>>stu[i].music>>stu[i].PE;
REP(i,1,n+1){
REP(j,i+1,n+1) if(ok(i,j)){
G[i].push_back(j);
G[j].push_back(i);
}
}
int ans=match();
printf("%d\n",n-ans/2);
}
return 0;
}
UVALive-3415 Guardian of Decency (最大独立集)的更多相关文章
- UVALive 3415 Guardian of Decency(二分图的最大独立集)
题意:老师在选择一些学生做活动时,为避免学生发生暧昧关系,就提出了四个要求.在他眼中,只要任意两个人符合这四个要求之一,就不可能发生暧昧.现在给出n个学生关于这四个要求的信息,求老师可以挑选出的最大学 ...
- uvalive 3415 Guardian Of Decency
题意: 有一个老师想组织学生出去旅游,为了避免他们之间有情侣产生,他制定了一系列的条件,满足这些条件之一,那么这些人理论上就不会成为情侣: 身高相差40cm:性别相同:喜欢的音乐风格不同:最喜欢的运动 ...
- UVALive3415 Guardian of Decency —— 最大独立集
题目链接:https://vjudge.net/problem/UVALive-3415 题解: 题意:选出尽可能多的人, 使得他(她)们之间不会擦出火花.即求出最大独立集. 1.因为性别有男女之分, ...
- Guardian of Decency UVALive - 3415 最大独立集=结点数-最大匹配数 老师带大学生旅游
/** 题目:Guardian of Decency UVALive - 3415 最大独立集=结点数-最大匹配数 老师带大学生旅游 链接:https://vjudge.net/problem/UVA ...
- POJ 2771 Guardian of Decency 【最大独立集】
传送门:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Tot ...
- Guardian of Decency(二分图)
Guardian of Decency Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submi ...
- 训练指南 UVALive - 3415(最大点独立集)
layout: post title: 训练指南 UVALive - 3415(最大点独立集) author: "luowentaoaa" catalog: true mathja ...
- POJ 2771 Guardian of Decency (二分图最大点独立集)
Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6133 Accepted: 25 ...
- uva 12083 Guardian of Decency (二分图匹配)
uva 12083 Guardian of Decency Description Frank N. Stein is a very conservative high-school teacher. ...
- poj——2771 Guardian of Decency
poj——2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5916 ...
随机推荐
- poj1952 BUY LOW, BUY LOWER【线性DP】【输出方案数】
BUY LOW, BUY LOWER Time Limit: 1000MS Memory Limit: 30000K Total Submissions:11148 Accepted: 392 ...
- SQL---->mySQl查看和更改端口
修改端口: 采用dmg方式安装的mysql,默认启动端口为3307,不是默认的3306.如果想改为3306,可以编辑 /Library/LaunchDaemons /com.Oracle.os ...
- UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 0: illegal multibyte sequence
使用Python写文件的时候,或者将网络数据流写入到本地文件的时候,大部分情况下会遇到:UnicodeEncodeError: 'gbk' codec can't encode character ' ...
- 关于java web的笔记2018-01-12
需求:1.写一个商品类,有商品编号.商品名称.商品分类.商品单价属性.2.写一个商品条目信息类,有商品和数量两个属性,有商品总价格方法.3.写一个购物车类,有添加商品方法.查看订单信息,删除商品,修改 ...
- lampp and testrail
https://wyzx.testrail.net szllq2000 http://129.0.1.228/testrail/ http://docs.gurock.com/testrail-adm ...
- string unicode utf8 ascii in python and js
http://www.jb51.net/article/62155.htm http://www.cnblogs.com/dkblog/archive/2011/03/02/1980644.html ...
- Python3、Unicode、UTF-8、编码
text = u'你好,今天天气不错' text print(text) text = '\u4f60\u597d\uff0c\u4eca\u5929\u5929\u6c14\u4e0d\u9519' ...
- Android仿今日头条手界面
public class MyIndicator extends HorizontalScrollView implements ViewPager.OnPageChangeListener { pr ...
- centos samba/squid 配置 samba配置 smbclient mount fstab自动挂载samba curl -xlocalhost:3128 www.qq.com squid配置 3128 DNSPOD 第二十七节课
centos samba/squid 配置 samba配置 smbclient mount fstab自动挂载samba curl -xlocalhost:3128 www.qq.com squ ...
- git-【三】理解工作区与暂存区的区别
基本概念 工作区:就是你在电脑上看到的目录,比如目录下testgit里的文件(.git隐藏目录版本库除外).或者以后需要再新建的目录文件等等都属于工作区范畴. 版本库(Repository ...