题目链接:传送门

I'm Telling the Truth

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2305    Accepted Submission(s): 1147

Problem Description
After this year’s college-entrance exam, the teacher did a survey in his class on students’ score. There are n students in the class. The students didn’t want to tell their teacher their exact score; they only told their teacher their rank in the province (in the form of intervals).

After asking all the students, the teacher found that some students didn’t tell the truth. For example, Student1 said he was between 5004th and 5005th, Student2 said he was between 5005th and 5006th, Student3 said he was between 5004th and 5006th, Student4 said he was between 5004th and 5006th, too. This situation is obviously impossible. So at least one told a lie. Because the teacher thinks most of his students are honest, he wants to know how many students told the truth at most.

Input
There is an integer in the first line, represents the number of cases (at most 100 cases). In the first line of every case, an integer n (n <= 60) represents the number of students. In the next n lines of every case, there are 2 numbers in each line, Xi and Yi (1 <= Xi <= Yi <= 100000), means the i-th student’s rank is between Xi and Yi, inclusive.
Output
Output 2 lines for every case. Output a single number in the first line, which means the number of students who told the truth at most. In the second line, output the students who tell the truth, separated by a space. Please note that there are no spaces at the head or tail of each line. If there are more than one way, output the list with maximum lexicographic. (In the example above, 1 2 3;1 2 4;1 3 4;2 3 4 are all OK, and 2 3 4 with maximum lexicographic)
Sample Input
2 4 5004 5005 5005 5006 5004 5006 5004 5006 7 4 5 2 3 1 2 2 2 4 4 2 3 3 4
Sample Output
3 2 3 4 5 1 3 5 6 7

解题思路:匈牙利算法模板,竟然没超时

#include <iostream>
#include <cstring>
#include <stdio.h>
#include <map>
#include <queue>using namespace std;
#define size1 1000060
#define size2 505
#define size3 100010struct Edge
{int node;Edge*next;
}m_edge[size1];
int girl[size3];
Edge*head[size2];
int Flag[size3];
int Ecnt,cnt;void init()
{Ecnt = cnt = 0;fill( girl , girl+size3 , 0 );fill( head , head+size2 , (Edge*)0 );
}//b能和g匹配
void mkEdge( int b , int g )
{m_edge[Ecnt].node = g;m_edge[Ecnt].next = head[b];head[b] = m_edge+Ecnt++;
}bool find( int x )
{for( Edge*p = head[x] ; p ; p = p->next ){int s = p->node;  //有好感的女生if( !Flag[s] ){Flag[s] = true;    //该女生在本轮匹配中被访问if( girl[s] == 0 || find(girl[s]) ){//女生没有对象或者另外一个男生能把这个妹子让给x男girl[s] = x;return true;}}}return false;
}//构建二分图
void Build( int n )
{int a,b;for( int i = 1 ; i <= n ; ++i ){scanf("%d%d",&a,&b);for( int j = a ; j <= b ; ++j ){mkEdge(i,j);}}
}int rec[size2];void solve( int n )
{for( int i = n ; i >= 1 ; --i ){fill( Flag , Flag+size3 , 0 );if( find(i) ){rec[cnt++] = i;}}
}int main()
{int T;scanf("%d",&T);while( T-- ){init();int n;scanf("%d",&n);Build(n);solve(n);printf("%d\n",cnt);printf("%d",rec[cnt-1]);for( int i = cnt-2 ; i >= 0 ; --i ){printf(" %d",rec[i]);}printf("\n");}return 0;
}

hdu3729—I'm Telling the Truth(二分图最大匹配)相关推荐

  1. HDU 3729 I'm Telling the Truth(二分图最大匹配)

    HDU 3729 I'm Telling the Truth(二分图最大匹配) http://acm.hdu.edu.cn/showproblem.php?pid=3729 题意: 一位老师想问N位同 ...

  2. I'm Telling the Truth(二分图匹配)

    原题 题意: 有n个学生,你想了解他们的成绩.每个人告诉你他们的名次区间在x~y之间(闭区间),你需要判断最多说真话的人数,并输出这些人的编号,多种情况时输出最大字典序的一组 思路 该题目乍一看像并查 ...

  3. 解题报告 (九) 二分图最大匹配

    文章目录 二分图最大匹配 解题报告 一.最大匹配模板题 HDU 1083 Courses HDU 2063 过山车 HDU 1528 Card Game Cheater HDU 1179 Olliva ...

  4. 【网络流24题】解题报告:A、飞行员配对方案问题(最大流求二分图最大匹配)

    A.飞行员配对方案问题 (二分图最大匹配)(最大流)[提高+/省选- ] 题目链接 [问题分析] 二分图最大匹配问题. [建模方法] 在二分图的基础上增加源S和汇T. 1.S向X集合中每个顶点连一条容 ...

  5. 【模板】匈牙利算法 二分图最大匹配题模板

    [任务] 给定一个二分图,用匈牙利算法求这个二分图的最大匹配数. [说明] 求最大匹配,那么我们希望每一个在左边的点都尽量找到右边的一个点和它匹配. 我们一次枚举左边的点x的所有出边指向的点y, 若y ...

  6. 51nod 2006 飞行员配对(二分图最大匹配) 裸匈牙利算法 求二分图最大匹配题

    题目: 题目已经说了是最大二分匹配题, 查了一下最大二分匹配题有两种解法, 匈牙利算法和网络流. 看了一下觉得匈牙利算法更好理解, 然后我照着小红书模板打了一遍就过了. 匈牙利算法:先试着把没用过的左 ...

  7. 2021牛客多校3 - Minimum grid(二分图最大匹配-最大流)

    题目链接:点击查看 题目大意:给出一个 n∗nn*nn∗n 的棋盘,其中有 mmm 个位置是需要填数字的位置,每个位置需要填 [0,k][0,k][0,k] 的数字中的其中一个,可以重复,现在给出每一 ...

  8. HDU - 1054 Strategic Game(最小点覆盖-二分图最大匹配)

    题目链接:点击查看 题目大意:给出一棵树,现在要在节点上放置士兵,每个士兵可以监视与其所在的节点直接相连的节点,问最少需要多少个士兵才能将整棵树都监视到 题目分析:求最少的节点,以保证每条边都有一个端 ...

  9. HDU - 2389 Rain on your Parade(Hopcroft-Krap算法求二分图最大匹配)

    题目链接:点击查看 题目大意:给出n个人和m个雨伞,t分钟后就要下雨了,现在给出每个人的坐标和速度,以及雨伞所在的坐标,每个雨伞只能容纳一个人,题目问最多有多少个人能不被淋到 题目分析:二分图最大匹配 ...

最新文章

  1. Open3d学习计划—高级篇 4(多视角点云配准)
  2. Windows 不能在 本地计算机 启动 SQL Server 服务
  3. StaicArray
  4. 2021-02-24 Python等比例压缩与质量处理图片
  5. linux磁盘分区表解读:只占64字节
  6. quartus状态机生成_生成器作为(快速失败)状态机
  7. iOS7应用开发1、菜鸟那点儿事儿
  8. 消息传递的图神经网络
  9. 贝叶斯优化优化参数,以Kmeans为例
  10. c语言单片机程序设计例,单片机 C语言 程序设计100例
  11. 利用Proteus 8.9运行stm32最简单的跑马灯程序
  12. 正则表达式:提取数字和小数点
  13. 值得看看的艺术影片 (转)
  14. 读书札记:瑞士法郎的因素
  15. Win7系统下插入新的usb设备都提示安装驱动失败的解决方法
  16. 转载 Fluent中的压力分类
  17. windows7运行软件出现找不到D3DCOMPILER_47.dll的解决办法
  18. C语言求解三个数的中间值
  19. html5图钉效果,新版图钉软件全方位升级
  20. DDD(领域驱动设计)分层架构

热门文章

  1. 综合布线工程常用计算简单公式
  2. java 反编译 错误_IDEA中使用javap反编译工具,出现找不到类的错误,解决方法
  3. java给图片加水印_java如何给图片加水印
  4. iOS进程间通讯方式
  5. Revit土建建模插件,BIM建模助手(土建插件)功能一览!
  6. PLC 西门子smart200 锁机 分期期付款 动态验证码
  7. VPP - 三层转发
  8. 遍历List容器时,元素不是你想删,想删就能删!
  9. 晶晨S905X3/S905D3/S912/S922X芯片的区别在哪里
  10. Fedora Linux