题目链接:传送门

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. String对象不可修改指的是对象本身不可修改,而不是引用不可修改。
  2. iOS开发多线程篇—线程安全
  3. 工作中Oracle常用的SQL
  4. 导致UPS蓄电池损坏的原因有哪些?
  5. Delphi XE2 之 FireMonkey 入门(18) - TLang(多语言切换的实现)
  6. f分布表完整图_【教育统计答疑】如何理解正态分布、均值分布、^2分布、t分布和F分布...
  7. 安卓10侧边返回_Android 之路 (10) - 集成滑动返回(SwipeBackLayout)
  8. Linux系统中设置静态ip地址
  9. python解包裹_python-之基本语法
  10. BZOJ_1096_[ZJOI2007]_仓库建设_(斜率优化动态规划+单调队列+特殊的前缀和技巧)
  11. 2010 模板下载 罗斯文_学生个人简历模板,简历制作技巧
  12. Spyder安装教程只需三步_保姆式无基础 2020/11/7最新版
  13. 逍遥书生服务器啥时候维护完毕,2020年8月18日定期维护解读
  14. 设计模式私家笔记——概述:设计模式是银弹吗?
  15. 怎么把电脑设为服务器共享文档,共享电脑设置 服务器
  16. 直接插入排序算法视频
  17. Unity批次合并渲染
  18. 微信公众号如何做好日常维护?
  19. 橡胶接头能承受的压力有多大
  20. PS5运行Linux,索尼发布新驱动 PS5手柄现已支持Linux系统用户

热门文章

  1. 任意角的正弦怎么用计算机算,任意角的正弦函数、余弦函数的定义、
  2. 一个可以AK IOI的算法——暴力
  3. 饿了么领取最大红包php源码,『开源』#饿了么美团外卖#一键领取手气最佳红包...
  4. Pat刷题真题乙级(4)
  5. 【面试题】类似国际象棋的棋子移动实现
  6. sql在插入语句使用子查询_SQL插入查询
  7. 困惑度perplexity
  8. 高频数据分析:使用数据透视
  9. 用VC++编写勾子程序(转)
  10. Nuxt.js - 最新自定义报错、缺省、404、500 定制化 error.vue(页面、接口报错时自动跳转到该自定义页面)支持自定义文案、状态码等功能