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 (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1700 Accepted Submission(s):
853
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.
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.
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)
#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(二分匹配_ 匈牙利算法)的更多相关文章
- HDU 3729 I'm Telling the Truth (二分匹配)
题意:给定 n 个人成绩排名区间,然后问你最多有多少人成绩是真实的. 析:真是没想到二分匹配,....后来看到,一下子就明白了,原来是水题,二分匹配,只要把每个人和他对应的区间连起来就好,跑一次二分匹 ...
- 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 ...
- hdu 3729 I'm Telling the Truth 二分图匹配
裸的二分图匹配.需要输出方案. #include<cstdio> #include<cstring> #include<vector> #include<al ...
- 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 ...
- HDU 2063:过山车(偶匹配,匈牙利算法)
过山车 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- HDU - 3729 I'm Telling the Truth(二分匹配)
题意:有n个人,每个人给出自己的名次区间,问最多有多少个人没撒谎,如果有多解,输出字典序最大的解. 分析: 1.因为字典序最大,所以从后往前分析. 2.假设后面的人没说谎,并将此作为已知条件,然后从后 ...
- hdu 2063 过山车 二分匹配(匈牙利算法)
简单题hdu2063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 过山车 Time Limit: 1000/1000 MS (Java/Ot ...
- HDU 1150:Machine Schedule(二分匹配,匈牙利算法)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu2063 最大二分匹配(匈牙利算法)
过山车 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- 从理论到实践,全方位认识DNS
从理论到实践,全方位认识DNS 2015-11-23 程序员之家 作者:selfboot 原文:http://segmentfault.com/a/1190000003956853 对于 DNS(Do ...
- java 集合 父类的使用子类的方法时候 底层自动转型为子类的数据类型
跟继承多态不一样 继承多态需要显示转型
- 【bzoj5157】[Tjoi2014]上升子序列 树状数组
题目描述 求一个数列本质不同的至少含有两个元素的上升子序列数目模10^9+7的结果. 题解 树状数组 傻逼题,离散化后直接使用树状数组统计即可.由于要求本质不同,因此一个数要减去它前一次出现时的贡献( ...
- jmeter之JDBC的使用
一.配置JDBC Request 1.添加需要的驱动jar包 使用不同的数据库,我们需要引入不同的jar包. 方式1:直接将jar包复制到jmeter的lib目录 mysql数据库:下载mysql- ...
- 【Java】JAVA-加密-DES加密代码详解
package util; import java.security.SecureRandom; import javax.crypto.spec.DESKeySpec; import javax.c ...
- Android开发性能优化总结(一)
安卓开发应用首先要讲究良好的用户体验,如果一款软件卡顿现象严重,不流畅,经常崩溃,那么将给用户带来极不良好的体验,从而损失用户. 在实际开发和学习中,我总结了一下关于安卓性能的优化,供大家参考交流. ...
- 【JavaScript】面向对象的程序设计
一.前言 接着上一篇的内容,继续JavaScript的学习. 二.内容 属性类型 //数据属性[Configurable] —— 能否通过delete删除属性从而重新定义属性,能否修改属 ...
- 【BZOJ3714】Kuglarz(最小生成树)
[BZOJ3714]Kuglarz(最小生成树) 题面 BZOJ Description 魔术师的桌子上有n个杯子排成一行,编号为1,2,-,n,其中某些杯子底下藏有一个小球,如果你准确地猜出是哪些杯 ...
- 扔几道sb题
1.给定一个长度为N的数列,A1, A2, ... AN,如果其中一段连续的子序列Ai, Ai+1, ... Aj(i <= j)之和是K的倍数,我们就称这个区间[i, j]是K倍区间. 你能求 ...
- 在C++程序中开启和禁用Windows设备的无线网卡的方法
原文链接地址:https://www.jb51.net/article/81340.htm 1.列出当前网卡:SetupDiEnumDeviceInfo 2.找出当前无线网卡的名字(用natvie w ...