比赛的时候没有想到二分图,一直在想dp和贪心。 原因是因为看到数据是100000所以直接就没有往二分图匹配上想。

现在想想。 因为二分图两边的太不对称了,60 和100000 , 如果用匈牙利算法考虑的话,左边的点应该可以很快的找到一个与之匹配的点。 如果边不多的话那么找起来也是很快的。

还是太弱。

I'm Telling the Truth

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

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
 
Recommend
zhouzeyong
 
// 题目数据比较水 ,用邻接表都不会超内存. 用邻接矩阵稍微优化也能过。。
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std; int n;
bool g[][];
int save[];
int mark[];
int pre[];
int mx,mi; int dfs(int s)
{
for(int i=mi;i<=mx;i++)
{
if(mark[i]==||g[s][i]==) continue;//表示不可达
mark[i]=;
if(pre[i]==-||dfs(pre[i])==)
{
pre[i]=s;
return ;
}
}
return ;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
mx=;
mi=;
memset(g,,sizeof(g));
scanf("%d",&n);
for(int i=;i<=n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
mx=max(mx,y);
mi=min(x,mi);
for(int j=x;j<=y;j++)
{
g[i][j]=;
}
}
memset(pre,-,sizeof(pre));
int ans=;
for(int i=n;i>=;i--)
{
memset(mark,,sizeof(mark));
if(dfs(i))
{
save[ans++]=i;
}
}
printf("%d\n",ans);
for(int i=ans-;i>;i--)
printf("%d ",save[i]);
printf("%d\n",save[]);
}
return ;
}

hdu3729(二分图)的更多相关文章

  1. 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/ ...

  2. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  3. POJ 2125 Destroying the Graph 二分图最小点权覆盖

    Destroying The Graph Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8198   Accepted: 2 ...

  4. bzoj4025 二分图

    支持加边和删边的二分图判定,分治并查集水之(表示我的LCT还很不熟--仅仅停留在极其简单的模板水平). 由于是带权并查集,并且不能路径压缩,所以对权值(到父亲距离的奇偶性)的维护要注意一下. 有一个小 ...

  5. hdu 1281 二分图最大匹配

    对N个可以放棋子的点(X1,Y1),(x2,Y2)......(Xn,Yn);我们把它竖着排看看~(当然X1可以对多个点~) X1   Y1 X2   Y2 X3   Y3 ..... Xn   Yn ...

  6. POJ 2226二分图最大匹配

    匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名.匈牙利算法是基于Hall定理中充分性证明的思想,它是二部图匹配最常见的算法,该算法的核心就是寻找增广路径,它是一种用增广路径求二分图 ...

  7. 二分图&网络流&最小割等问题的总结

    二分图基础: 最大匹配:匈牙利算法 最小点覆盖=最大匹配 最小边覆盖=总节点数-最大匹配 最大独立集=点数-最大匹配 网络流: 技巧: 1.拆点为边,即一个点有限制,可将其转化为边 BZOJ1066, ...

  8. POJ2195 Going Home[费用流|二分图最大权匹配]

    Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22088   Accepted: 11155 Desc ...

  9. 洛谷P2055 [ZJOI2009]假期的宿舍 [二分图最大匹配]

    题目描述 学校放假了 · · · · · · 有些同学回家了,而有些同学则有以前的好朋友来探访,那么住宿就是一个问题.比如 A 和 B 都是学校的学生,A 要回家,而 C 来看B,C 与 A 不认识. ...

随机推荐

  1. 应用zip压缩的javascript以及Egret H5游戏实战

    代码地址如下:http://www.demodashi.com/demo/11039.html 主要起因是策划对最快进入登录界面有硬性要求(3秒),那么最开始加载的文件越小越好.对H5的游戏程序进行压 ...

  2. asp 支付宝 企业版 接口 支持网银接口 ,网银直接支付

    asp 支付宝 企业版 接口 支持网银接口 ,网银直接支付 仅仅是多了一个defalutbank的參数. 详细看 open.alipay.com <% ' 类名:AlipaySubmit ' 功 ...

  3. HTML-HTML5+CSS3权威指南阅读(五、深入理解viewport)

    1.手机浏览器与桌面浏览器的不同 现在手机浏览器的显示分辨率与桌面浏览器差不多,但是手机的尺寸比电脑要小很多.一个没做过响应式处理的网站,在手机和电脑上显示完全一样的内容, 不可避免的会出现字体被缩小 ...

  4. unity3d对象的克隆

    对象克隆,需要有一个预制对象. 首先创建一个预制对象,将其命名为earth,并将材质包附着上去,如下图所示: 然后点住“earth”拖入Assets>Prefabs文件夹,此时earth文字变成 ...

  5. PayPal 对接

    时间:2019-1-29 15:39:39 文章相应链接: 官方SDK:https://developer.paypal.com/docs/api/rest-sdks/ 官方API:https://d ...

  6. photoshop 动作 自己定义快捷键 播放选定的动作

    今天在制作一组效果图.要用到动作.而且是同一个动作,便在网上寻找"播放选定的动作"就是那个三角形播放button的快捷键. 预期这样会大大加快制作过程. 首先制作好动作. 然后,在 ...

  7. Docker 私有仓库最简便的搭建方法

    http://blog.csdn.net/wangtaoking1/article/details/44180901/ Docker学习笔记 — Docker私有仓库搭建http://www.jian ...

  8. AlarmManager研究

    1.概述 在Android系统中,闹钟和唤醒功能都是由Alarm Manager Service控制并管理的.我们所熟悉的RTC闹钟以及定时器都和它有莫大的关系.为了便于称呼,我常常也把这个servi ...

  9. Postman 常用操作

    一,入参为json 格式 实例:添加学生信息,这个接口是用来讲入参式json 类型的 二,上传文件 三,添加header 信息 实例:获取所有学生信息 四,添加cookie以及身份验证 实例:学生金币 ...

  10. lantin1

    Latin1是ISO-8859-1的别名,有些环境下写作Latin-1. ISO-8859-1编码是单字节编码,向下兼容ASCII,其编码范围是0x00-0xFF,0x00-0x7F之间完全和ASCI ...