题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3729

I'm Telling the Truth

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

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
 
Source
 
 
题目大意:每个人说一个自己成绩排名的区间,但是根据他们所说的会产生矛盾。现在给你一个任务,要你来判断到底谁说的是正确的!输出说真话人的数量以及说真话的人的序号。
解题思路:我们可以把区间的左部分看做是二分图的左枝,区间的右部分看做是二分图的右枝。
特别注意:输出是有要求的,有很多种情况的时候,输出最大的字典序。
 
详见代码。
 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int n;
int ok[+],vis[+],as[+];
struct node{
int x,y;
}s[];
int num[+]; bool Find(int x)
{
for (int i=s[x].x;i<=s[x].y;i++)
{
if (!vis[i])
{
vis[i]=;
if (!ok[i])
{
as[x]=;
ok[i]=x;
return true;
}
else
{
if (Find(ok[i]))
{
as[x]=;
ok[i]=x;
return true;
}
}
}
}
return false;
} int main()
{
int T;
int x,y; scanf("%d",&T);
while (T--)
{
int k=;
scanf("%d",&n);
memset(as,,sizeof(as));
memset(ok,,sizeof(ok));
int ans=;
for (int i=;i<=n;i++)
{
scanf("%d%d",&s[i].x,&s[i].y);
}
for (int i=n;i>;i--)
{
memset(vis,,sizeof(vis));
if (Find(i))
ans++;
}
printf ("%d\n",ans);
for (int i=n;i>=;i--)
{
if (as[i]==)
{
num[k++]=i;
//cout<<num[k-1]<<endl;
}
}
for (int i=k-;i>;i--)
printf ("%d ",num[i]);
printf ("%d\n",num[]);
}
return ;
}

hdu 3729 I'm Telling the Truth(二分匹配_ 匈牙利算法)的更多相关文章

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

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

  2. hdu 1498 50 years, 50 colors(二分匹配_匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1498 50 years, 50 colors Time Limit: 2000/1000 MS (Ja ...

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

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

  4. HDU 2389 Rain on your Parade(二分匹配,Hopcroft-Carp算法)

    Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Ot ...

  5. HDU 2063:过山车(偶匹配,匈牙利算法)

    过山车 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

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

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

  7. hdu 2063 过山车 二分匹配(匈牙利算法)

    简单题hdu2063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 过山车 Time Limit: 1000/1000 MS (Java/Ot ...

  8. HDU 1150:Machine Schedule(二分匹配,匈牙利算法)

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. hdu2063 最大二分匹配(匈牙利算法)

    过山车 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

随机推荐

  1. SQL入门之集合操作

    尽管可以在与数据库交互时一次只处理一行数据,但实际上关系数据库通常处理的都是数据的集合.在数学上常用的集合操作为:并(union),交(intersect),差(except).对于集合运算必须满足下 ...

  2. [区分] 1.计算机网络/internet(互联网) 2.Internet(因特网) 3.www/web(万维网)

    internet(互联网或互连网)是一个通用名词,泛指由多个计算机网络互联而成的虚拟网络.Inernet(因特网)是一个专用名词,指当前全球最大的.开放的.由众多网络相互连接而成的特定的计算机网络,它 ...

  3. DjangoORM使用mysql注意

    注意事项1:需要在project下的setting里面做设置.让Django生成MySQL类型的数据库. 注意事项2:在Django内部,连MySQL的时候,需要添加下面2句代码: 4.******* ...

  4. 【NuGet】使用NuGet打包并发布至ProGet过程 (步骤详细,附python脚本)【上篇】

    一.基本知识 (1)NuGet : NuGet是一个为大家所熟知的Visual Studio扩展,通过这个扩展,开发人员可以非常方便地在Visual Studio中安装或更新项目中所需要的第三方组件, ...

  5. Linux内核分析第四周学习总结——系统调用的工作机制

    Linux内核分析第四周学习总结--系统调用的工作机制 内核态 执行级别高,可以执行特权指令,访问任意物理地址,在intel X86 CPU的权限分级为0级. 用户态 执行级别低,只能访问0x0000 ...

  6. 洛谷 P1924 poj 1038

    Description: 给你一个n * m的方格纸,有一些格子无法被覆盖,然后用2*3的格子覆盖这个方格纸,问你最多能放多少个格子 神级状压 为了弄清楚这道题翻了无数篇解题报告,最后终于搞明白了 用 ...

  7. dorado7常用内容

    1.dataset添加数据this.get("#dsProduct").getData().insert();或者this.get("#dsProduct"). ...

  8. 《剑指offer》— JavaScript(9)变态跳台阶

    变态跳台阶 题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级--它也可以跳上n级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 实现代码 function jumpFloor(number) { ...

  9. 根据数据库连接的java.sql.Connection获取数据库名称

    // 获取数据库的元数据信息 DatabaseMetaData metaData = conn.getMetaData(); // 获取数据库名称的方法 System.out.println(meta ...

  10. 循环神经网络 RNN

    随着科学技术的发展以及硬件计算能力的大幅提升,人工智能已经从几十年的幕后工作一下子跃入人们眼帘.人工智能的背后源自于大数据.高性能的硬件与优秀的算法的支持.2016年,深度学习已成为Google搜索的 ...