题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=3729

题目意思:

有n个学生,老师询问每个学生的排名,每个学生都告诉了一个排名区间,求可能的最多的学生说实话的个数,以及那些学生的标号,有相同的则输出字典序最大的。

解题思路:

这题贪心只能求出个数,但要求字典序最大,则须用二分匹配。

将学生标号放到一个集合A里,另外一个集合B放排名。对于每个学生可能在的排名点,建一条边。从学生标号大的开始匹配。

代码

  1. #include<iostream>
  2. #include<cmath>
  3. #include<cstdio>
  4. #include<sstream>
  5. #include<cstdlib>
  6. #include<string>
  7. #include<cstring>
  8. #include<algorithm>
  9. #include<vector>
  10. #include<map>
  11. #include<set>
  12. #include<stack>
  13. #include<list>
  14. #include<queue>
  15. #include<ctime>
  16. #include<bitset>
  17. #define eps 1e-6
  18. #define INF 0x3f3f3f3f
  19. #define PI acos(-1.0)
  20. #define ll __int64
  21. #define LL long long
  22. #define lson l,m,(rt<<1)
  23. #define rson m+1,r,(rt<<1)|1
  24. #define M 1000000007
  25. #pragma comment(linker, "/STACK:1024000000,1024000000")
  26. using namespace std;
  27.  
  28. #define Maxn 65
  29. #define Maxm 110000
  30.  
  31. int cx[Maxn],cy[Maxm],nx,ny;
  32. bool vis[Maxm];
  33. vector<int>g[Maxn];
  34.  
  35. int path(int u)
  36. {
  37. for(int v=0;v<g[u].size();v++)
  38. {
  39. if(!vis[g[u][v]])
  40. {
  41. vis[g[u][v]]=true; //从这个点找,要么找到对应的,要么找不到
  42. if(cy[g[u][v]]==-1||path(cy[g[u][v]]))
  43. {
  44. cy[g[u][v]]=u;
  45. cx[u]=g[u][v];
  46. return 1;
  47. }
  48. }
  49. }
  50. return 0;
  51. }
  52. int MaxMatch()
  53. {
  54. memset(cx,-1,sizeof(cx));
  55. memset(cy,-1,sizeof(cy));
  56.  
  57. int ans=0;
  58. for(int i=nx;i>=1;i--) //满足字典序最大
  59. {
  60. if(cx[i]==-1)
  61. {
  62. memset(vis,false,sizeof(vis));
  63. ans+=path(i);
  64. }
  65. }
  66. return ans;
  67. }
  68. int main()
  69. {
  70. int t;
  71.  
  72. scanf("%d",&t);
  73. while(t--)
  74. {
  75. scanf("%d",&nx);
  76.  
  77. for(int i=1;i<=nx;i++)
  78. {
  79. g[i].clear();
  80. int a,b;
  81. scanf("%d%d",&a,&b);
  82. for(int j=a;j<=b;j++) //将所有的可能排名点建一条边
  83. g[i].push_back(j);
  84. }
  85. int ans=MaxMatch();
  86. printf("%d\n",ans);
  87. for(int i=1;i<=nx;i++)
  88. {
  89. if(cx[i]!=-1)
  90. {
  91. printf("%d",i);
  92. ans--;
  93. if(ans)
  94. putchar(' ');
  95. else
  96. putchar('\n');
  97. }
  98. }
  99. }
  100. return 0;
  101. }

二分图的最大匹配-hdu-3729-I'm Telling the Truth的更多相关文章

  1. hdu 3729 I'm Telling the Truth(二分匹配_ 匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3729 I'm Telling the Truth Time Limit: 2000/1000 MS ( ...

  2. hdu 3729 I'm Telling the Truth 二分图匹配

    裸的二分图匹配.需要输出方案. #include<cstdio> #include<cstring> #include<vector> #include<al ...

  3. HDU 3729 I'm Telling the Truth (二分匹配)

    题意:给定 n 个人成绩排名区间,然后问你最多有多少人成绩是真实的. 析:真是没想到二分匹配,....后来看到,一下子就明白了,原来是水题,二分匹配,只要把每个人和他对应的区间连起来就好,跑一次二分匹 ...

  4. HDU - 3729 I'm Telling the Truth(二分匹配)

    题意:有n个人,每个人给出自己的名次区间,问最多有多少个人没撒谎,如果有多解,输出字典序最大的解. 分析: 1.因为字典序最大,所以从后往前分析. 2.假设后面的人没说谎,并将此作为已知条件,然后从后 ...

  5. hdu3729 I'm Telling the Truth (二分图的最大匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=3729 I'm Telling the Truth Time Limit: 2000/1000 MS (Java/ ...

  6. HDU 3729 I&#39;m Telling the Truth(二部图最大匹配+结果输出)

    职务地址:HDU 3729 二分图最大匹配+按字典序输出结果. 仅仅要从数字大的開始匹配就能够保证字典序最大了.群里有人问. . 就顺手写了这题. . 代码例如以下: #include <ios ...

  7. hdu 3729(二分图最大匹配)

    I'm Telling the Truth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. UVALive 5033 I'm Telling the Truth 二分图最大匹配(略有修改)

    I - I'm Telling the Truth Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu ...

  9. HDU 2389 Rain on your Parade / HUST 1164 4 Rain on your Parade(二分图的最大匹配)

    HDU 2389 Rain on your Parade / HUST 1164 4 Rain on your Parade(二分图的最大匹配) Description You're giving a ...

  10. HDU 2444 The Accomodation of Students 二分图判定+最大匹配

    题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...

随机推荐

  1. Objective-C学习篇05—Foundation框架简介

    iOS中所谓的框架,说到底就是一个目录,iOS提供了很多我们可以在应用程序中调用的框架.许多应用程序都使用了如Foundation.UIKit和Core Graphics这些框架.根据你为应用程序选择 ...

  2. Hive学习之五 《Hive进阶—UDF操作案例》 详解

    hive—UDF操作 udf的操作过程: 在HIVE会话中add 自定义函数的jar文件,然后创建function,继而使用函数. 下面就以下面课题为例: 课题:统计每个活动的PV和UV 一.Java ...

  3. 模拟vector

    实现了vector的模板,insert, erase, push_back, iterator #include<iostream> #include<string.h> #i ...

  4. mysql for linux 数据库的安装过程

    mysql for linux 数据库的安装过程 l  安装版本:mysql-advanced-5.6.12-linux-glibc2.5-x86_64.tar.gz ,此版本是绿色版本,只需要将其解 ...

  5. REST简介及设计原则

    rest,即REST(Representational State Transfer表述性状态转移)是一种针对网络应用的设计和开发方式,可以降低开发的复杂性,提高系统的可伸缩性. 简介 REST (R ...

  6. Thinkphp 验证码、文件上传

    一.验证码 验证码参数 例题:登录时验证下验证码 LoginController.class.php <?php namespace Home\Controller; use Think\Con ...

  7. 网易DBA私享会分享会笔记1

    1.mysql生态+DBA职业发展世界范围流行的开源关系型的数据库关系型数据库:mysql,oracle,sql server,access,postgresql,sqlite,sybase,info ...

  8. zend studio设置

    1.字体设置: 第一步:进入设置窗口    windows -> preferences 第二步:进入修改字体的选项卡.    General -> Appearance -> Co ...

  9. php的session实现

    对于两次http请求,如果第一次http请求的重要数据要被第二次请求获取,办法是将第一次http请求数据保存下来,保存的办法很多,大体上有使用数据库,缓存,文件等等,那么php中的session实现实 ...

  10. Reflow、Repaint 性能优化

    涉及到操作大量Dom节点及其样式时,有时感觉画面不顺畅,殊不知浏览器亚历山大了.所以我们心里面一定得清楚 Reflow(回流).Repaint(重绘). 浏览器根据每个Dom节点的样式,包括(大小,颜 ...