比赛的时候没有想到二分图,一直在想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. <转>得到其它进程的命令行

    #include <windows.h> #include <stdio.h> #define ProcessBasicInformation 0 typedef struct ...

  2. MyEclipse 注释乱码问题

    解决MyEclipse 中 import项目,注释是乱码问题:

  3. C#指南,重温基础,展望远方!(5)C#语句

    程序操作使用语句进行表示. C# 支持几种不同的语句,其中许多语句是从嵌入语句的角度来定义的. 使用代码块,可以在允许编写一个语句的上下文中编写多个语句. 代码块是由一系列在分隔符 { 和 } 内编写 ...

  4. /usr/lib64/libssl.so.10: no version information available (required by ./mongod)

    启动mongodb时,日志提示以下信息: ./mongod: /usr/lib64/libssl.so.10: no version information available (required b ...

  5. DOS命令 bat-call的用法

    call 从批处理程序调用另一个批处理程序 call有几种用法 第一种用法,也就是最常用的一种,调用另一个批处理,在被调用的批处理执行完后在执行call下面的命令.如: @echo off call ...

  6. jquery 在ul中取得第一级的li

    在ul中取得第一级的li <div id='demo1'> <ul> <li id='1'>1<li> <li id='2'>2<li ...

  7. Python爬去图片实例,python 爬取图片

    # coding:utf-8 import requests import re import time proxies = { "http": "http://124. ...

  8. vivado设计一:建立第一个入门工程(基于zybo)

    vivado设计一:建立第一个入门工程(基于zybo) 0赞 发表于 2014/6/17 23:03:25 阅读(8777) 评论(4) 软件:vivado 2013.4 电脑:xp系统 硬件:zyb ...

  9. [elk]elasticsearch5.0及head插件安装

    ElasticSearch2.3/2.4升级到ElasticSearch5.0 参考文档(排名不分先后)https://www.elastic.co/guide/en/elasticsearch/re ...

  10. PHPCMS 学习

    1.碎片管理2.为了升级操作 MY_ thinkphp为大写phpcms里面也是大写 然后继承如果加构造函数要调用一次父类的构造函数,最好在最上面调用 final 不可重写 重写最好调用一次paren ...