比赛的时候没有想到二分图,一直在想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. Python-Sublime Text3 激活码

    1.点击菜单-help-Enter License 2.输入以下内容中的一个 —– BEGIN LICENSE —– Michael Barnes Single User License EA7E- ...

  2. 安装python3.6后使用pip报错

    安装python3.6后,pip是一起安装好的,安装目录再C:\Programs\Python\Python36-32\Scripts中. 在python终端模式下使用pip出现错误如下: 错误原因: ...

  3. Android_JarZip压缩和解压文件

        本文资料来自<android开发权威指南> AndroidSDK中提供了java.util.jar和java.util.zip包中的若干类和接口来完成. 压缩文件基本步骤: 1.创 ...

  4. TextView中超链接拦截

    TextView中的超链接点击时,其实是通过Intent方式的,因此会调用Activity中的startActivity(Intent intent)方法,所以可在此方法中做些简单的拦截操作 例如拦截 ...

  5. PHPCMS v9.6.0后台getshell

    思路来自于 http://www.cnbraid.com/2016/09/18/phpcms/ 这里自己复现了一下,自己写了一下 因为是后台的,还得登陆两次..所以不好用,主要是学习学习 漏洞来自于R ...

  6. 上传图片时,使用JS获得图片文件大小

    这个方法用于获得图片文件的大小: 在FF,Chrome,IE6,IE7,IE8可用,不支持IE9+.(如果是IE9就需要flash插件了) var getSize = function(oFile,c ...

  7. [转]OpenMP中的private/firstprivate/lastprivate/threadprivate之间的比较

    转自:http://blog.csdn.net/gengshenghong/article/details/6985431 private/firstprivate/lastprivate/threa ...

  8. impala+hdfs+csv格式文件

    [创建目录]hdfs dfs -mkdir -p /user/hdfs/sample_data/csv/devicehdfs dfs -mkdir -p /user/hdfs/sample_data/ ...

  9. android之ViewPager修改滑动速度

    在android中,使用过viewpager的人都清楚,我们如果使用viewpager进行滑动时,如果通过手指滑动来进行的话,可以根据手指滑动的距离来实现,但是如果通过setCurrentItem函数 ...

  10. dva学习---effects异步中通过select获取当前的state

    根据 在组件中dispatch一个action的例子中,如果要在effects中对于param数据和当前的state数据进行再出处理,这里怎么获取state呢?采用select,如下:       e ...