题目大意:一个老师要带一些学生去春游,但是要带的学生中任意两个人都满足下面四个条件中的至少一个: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 (最大独立集)的更多相关文章

  1. UVALive 3415 Guardian of Decency(二分图的最大独立集)

    题意:老师在选择一些学生做活动时,为避免学生发生暧昧关系,就提出了四个要求.在他眼中,只要任意两个人符合这四个要求之一,就不可能发生暧昧.现在给出n个学生关于这四个要求的信息,求老师可以挑选出的最大学 ...

  2. uvalive 3415 Guardian Of Decency

    题意: 有一个老师想组织学生出去旅游,为了避免他们之间有情侣产生,他制定了一系列的条件,满足这些条件之一,那么这些人理论上就不会成为情侣: 身高相差40cm:性别相同:喜欢的音乐风格不同:最喜欢的运动 ...

  3. UVALive3415 Guardian of Decency —— 最大独立集

    题目链接:https://vjudge.net/problem/UVALive-3415 题解: 题意:选出尽可能多的人, 使得他(她)们之间不会擦出火花.即求出最大独立集. 1.因为性别有男女之分, ...

  4. Guardian of Decency UVALive - 3415 最大独立集=结点数-最大匹配数 老师带大学生旅游

    /** 题目:Guardian of Decency UVALive - 3415 最大独立集=结点数-最大匹配数 老师带大学生旅游 链接:https://vjudge.net/problem/UVA ...

  5. POJ 2771 Guardian of Decency 【最大独立集】

    传送门:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS   Memory Limit: 65536K Tot ...

  6. Guardian of Decency(二分图)

    Guardian of Decency Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submi ...

  7. 训练指南 UVALive - 3415(最大点独立集)

    layout: post title: 训练指南 UVALive - 3415(最大点独立集) author: "luowentaoaa" catalog: true mathja ...

  8. POJ 2771 Guardian of Decency (二分图最大点独立集)

    Guardian of Decency Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6133   Accepted: 25 ...

  9. uva 12083 Guardian of Decency (二分图匹配)

    uva 12083 Guardian of Decency Description Frank N. Stein is a very conservative high-school teacher. ...

  10. poj——2771 Guardian of Decency

    poj——2771    Guardian of Decency Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5916   ...

随机推荐

  1. 每次收到的 HTTP 请求,就可以打开一个 SqlSession,返回一个响应,就关闭它

    mybatis – MyBatis 3 | 入门 http://www.mybatis.org/mybatis-3/zh/getting-started.html 作用域(Scope)和生命周期 理解 ...

  2. FPN(feature pyramid networks)

    多尺度的object detection算法:FPN(feature pyramid networks). 原来多数的object detection算法都是只采用顶层特征做预测,但我们知道低层的特征 ...

  3. Python开发【Tornado】:异步Web服务(二)

    真正的 Tornado 异步非阻塞 前言: 其中 Tornado 的定义是 Web 框架和异步网络库,其中他具备有异步非阻塞能力,能解决他两个框架请求阻塞的问题,在需要并发能力时候就应该使用 Torn ...

  4. logger类

    日志模块logging的四大组件: logger: 志类应用程序往往通调用提供api记录志handler: 志信息处理志发送(保存)同目标域filter: 志信息进行滤formatter:志格式化 L ...

  5. Openstack(十二)部署neuron(计算节点)

    在计算节点安装 12.1安装neuron(计算节点) # yum install openstack-neutron-linuxbridge ebtables ipset –y 12.2配置neutr ...

  6. 数据库知识,mysql索引原理

    1:innodb底层实现原理:https://blog.csdn.net/u012978884/article/details/52416997 2:MySQL索引背后的数据结构及算法原理    ht ...

  7. c primer plus(五版)编程练习-第七章编程练习

    1.编写一个程序.该程序读取输入直到遇到#字符,然后报告读取的空格数目.读取的换行符数目以及读取的所有其他字符数目. #include<stdio.h> #include<ctype ...

  8. Exhibitor(zookeeper监控工具)

    具体看github上的文档,很详细https://github.com/soabase/exhibitor/wiki/Running-Exhibitor 一. 这个是Netflix出品的一个监控工具, ...

  9. gcc安装多个版本

    http://blog.csdn.net/chid/article/details/6251781

  10. linux centos7 erlang rabbitmq安装

    最终的安装目录为/opt/erlang 和 /opt/rabbitmq wget http://erlang.org/download/otp_src_21.0.tar.gztar zxvf otp_ ...