题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34831

【思路】

二分图的最大独立集。

即在二分图中选取最多的点,使点与点之间不相邻。

最大独立集为最小覆盖集的补集。

男者X结点,女者Y结点,连边(Xi,Yj)当且仅当两者4个条件都不满足。

【代码】

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<vector>
  4. #include<iostream>
  5. #include<algorithm>
  6. using namespace std;
  7.  
  8. const int maxn = +;
  9. const int maxl = ;
  10.  
  11. bool T[maxn];
  12. int lky[maxn];
  13. vector<int> G[maxn];
  14.  
  15. bool match(int u) {
  16. for(int i=;i<G[u].size();i++) {
  17. int v=G[u][i];
  18. if(!T[v]) {
  19. T[v]=;
  20. if(!lky[v] || match(lky[v])) {
  21. lky[v]=u;
  22. return true;
  23. }
  24. }
  25. }
  26. return false;
  27. }
  28.  
  29. int n;
  30. char sex[maxn][],mus[maxn][maxl],pe[maxn][maxl];
  31. int h[maxn];
  32.  
  33. int main() {
  34. int k;
  35. scanf("%d",&k);
  36. while(k--) {
  37. scanf("%d",&n);
  38. for(int i=;i<=n;i++) G[i].clear();
  39. for(int i=;i<=n;i++) {
  40. scanf("%d%s%s%s",&h[i],sex[i],mus[i],pe[i]);
  41. for(int j=;j<i;j++)
  42. if(sex[j][]!=sex[i][] && abs(h[i]-h[j])<= && strcmp(mus[i],mus[j])== && strcmp(pe[i],pe[j])!=)
  43. if(sex[i][]=='M') G[i].push_back(j); else G[j].push_back(i);
  44. }
  45. memset(lky,,sizeof(lky));
  46. int ans=;
  47. for(int i=;i<=n;i++) {
  48. memset(T,,sizeof(T));
  49. if(match(i)) ans++;
  50. }
  51. printf("%d\n",n-ans);
  52. }
  53. return ;
  54. }

UVAlive3415 Guardian of Decency(最大独立集)的更多相关文章

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

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

  2. UVALive-3415 Guardian of Decency (最大独立集)

    题目大意:一个老师要带一些学生去春游,但是要带的学生中任意两个人都满足下面四个条件中的至少一个:1.性别相同:2.身高差大与40公分:3.最喜欢的音乐类型不同:4.最喜欢的体育运动相同.问老师最多能带 ...

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

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

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

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

  5. Guardian of Decency(二分图)

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

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

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

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

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

  8. poj——2771 Guardian of Decency

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

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

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

随机推荐

  1. .net 学习路线感想

    从上到大学到现在工作,已经有六年多了,发现学习编程到以开发为工作也是一个挺长的过程的. 大学中,从c语言到java.C#到其他各种语言的学习,还有其他知识的学习如:数据库(oracle.sql Ser ...

  2. Scrum教练不应兼任product owner

    ScrumMasters Should Not Also Be Product Owners(中文翻译) December 2, 2014 by Mike Cohn 翻译:2015.2.18 by o ...

  3. 玩转CSLA.NET小技巧系列一:跳转页面丢失session,如何解决

    很少写代码,最近在写代码被登录难倒了,这丫的一直在跟我较劲 每次登录完跳转到首页后还是未登录状态 if (ModelState.IsValid) { bool isSuccess = FI.Finan ...

  4. 最简单的基于FFmpeg的移动端例子:IOS 视频解码器-保存

    ===================================================== 最简单的基于FFmpeg的移动端例子系列文章列表: 最简单的基于FFmpeg的移动端例子:A ...

  5. Using GUID to generate the unique file name in C#

    GUID, the abbreviation of "Global Unique Identifier", is a unique reference number used as ...

  6. 【深度解析】Google第二代深度学习引擎TensorFlow开源

    作者:王嘉俊 王婉婷 TensorFlow 是 Google 第二代深度学习系统,今天宣布完全开源.TensorFlow 是一种编写机器学习算法的界面,也可以编译执行机器学习算法的代码.使用 Tens ...

  7. cocos2dx ease 公式

    所有ease计算公式都在CCTweenFunction.cpp里.

  8. nginx+php,502错误

    502错误基本就是php进程执行中挂了,其中有个原因就可能是进程执行超时设置导致的比如这个: ; The timeout for serving a single request after whic ...

  9. yii2源码学习笔记(四)

    继续了解组件Component.php /** * Returns a value indicating whether a property is defined for this componen ...

  10. Js随机数--网页版的体育彩票选号器

    <script> function Quickpick() { var ball for( ball = 0; ball < 5; ball++) { this[ball] = pa ...