UVAlive3415 Guardian of Decency(最大独立集)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34831
【思路】
二分图的最大独立集。
即在二分图中选取最多的点,使点与点之间不相邻。
最大独立集为最小覆盖集的补集。
男者X结点,女者Y结点,连边(Xi,Yj)当且仅当两者4个条件都不满足。
【代码】
- #include<cstdio>
- #include<cstring>
- #include<vector>
- #include<iostream>
- #include<algorithm>
- using namespace std;
- const int maxn = +;
- const int maxl = ;
- bool T[maxn];
- int lky[maxn];
- vector<int> G[maxn];
- bool match(int u) {
- for(int i=;i<G[u].size();i++) {
- int v=G[u][i];
- if(!T[v]) {
- T[v]=;
- if(!lky[v] || match(lky[v])) {
- lky[v]=u;
- return true;
- }
- }
- }
- return false;
- }
- int n;
- char sex[maxn][],mus[maxn][maxl],pe[maxn][maxl];
- int h[maxn];
- int main() {
- int k;
- scanf("%d",&k);
- while(k--) {
- scanf("%d",&n);
- for(int i=;i<=n;i++) G[i].clear();
- for(int i=;i<=n;i++) {
- scanf("%d%s%s%s",&h[i],sex[i],mus[i],pe[i]);
- for(int j=;j<i;j++)
- if(sex[j][]!=sex[i][] && abs(h[i]-h[j])<= && strcmp(mus[i],mus[j])== && strcmp(pe[i],pe[j])!=)
- if(sex[i][]=='M') G[i].push_back(j); else G[j].push_back(i);
- }
- memset(lky,,sizeof(lky));
- int ans=;
- for(int i=;i<=n;i++) {
- memset(T,,sizeof(T));
- if(match(i)) ans++;
- }
- printf("%d\n",n-ans);
- }
- return ;
- }
UVAlive3415 Guardian of Decency(最大独立集)的更多相关文章
- UVALive3415 Guardian of Decency —— 最大独立集
题目链接:https://vjudge.net/problem/UVALive-3415 题解: 题意:选出尽可能多的人, 使得他(她)们之间不会擦出火花.即求出最大独立集. 1.因为性别有男女之分, ...
- UVALive-3415 Guardian of Decency (最大独立集)
题目大意:一个老师要带一些学生去春游,但是要带的学生中任意两个人都满足下面四个条件中的至少一个:1.性别相同:2.身高差大与40公分:3.最喜欢的音乐类型不同:4.最喜欢的体育运动相同.问老师最多能带 ...
- 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 ...
- 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 ...
- UVALive 3415 Guardian of Decency(二分图的最大独立集)
题意:老师在选择一些学生做活动时,为避免学生发生暧昧关系,就提出了四个要求.在他眼中,只要任意两个人符合这四个要求之一,就不可能发生暧昧.现在给出n个学生关于这四个要求的信息,求老师可以挑选出的最大学 ...
随机推荐
- .net 学习路线感想
从上到大学到现在工作,已经有六年多了,发现学习编程到以开发为工作也是一个挺长的过程的. 大学中,从c语言到java.C#到其他各种语言的学习,还有其他知识的学习如:数据库(oracle.sql Ser ...
- Scrum教练不应兼任product owner
ScrumMasters Should Not Also Be Product Owners(中文翻译) December 2, 2014 by Mike Cohn 翻译:2015.2.18 by o ...
- 玩转CSLA.NET小技巧系列一:跳转页面丢失session,如何解决
很少写代码,最近在写代码被登录难倒了,这丫的一直在跟我较劲 每次登录完跳转到首页后还是未登录状态 if (ModelState.IsValid) { bool isSuccess = FI.Finan ...
- 最简单的基于FFmpeg的移动端例子:IOS 视频解码器-保存
===================================================== 最简单的基于FFmpeg的移动端例子系列文章列表: 最简单的基于FFmpeg的移动端例子:A ...
- Using GUID to generate the unique file name in C#
GUID, the abbreviation of "Global Unique Identifier", is a unique reference number used as ...
- 【深度解析】Google第二代深度学习引擎TensorFlow开源
作者:王嘉俊 王婉婷 TensorFlow 是 Google 第二代深度学习系统,今天宣布完全开源.TensorFlow 是一种编写机器学习算法的界面,也可以编译执行机器学习算法的代码.使用 Tens ...
- cocos2dx ease 公式
所有ease计算公式都在CCTweenFunction.cpp里.
- nginx+php,502错误
502错误基本就是php进程执行中挂了,其中有个原因就可能是进程执行超时设置导致的比如这个: ; The timeout for serving a single request after whic ...
- yii2源码学习笔记(四)
继续了解组件Component.php /** * Returns a value indicating whether a property is defined for this componen ...
- Js随机数--网页版的体育彩票选号器
<script> function Quickpick() { var ball for( ball = 0; ball < 5; ball++) { this[ball] = pa ...