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): 1427    Accepted Submission(s): 719

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

题意:有N(<=60)个人,说了自己的排名在[Ai,Bi]中,(1<=Ai Bi<=10^5),他们说的排名可能冲突,求最多有多少人说实话,并输出字典序最大的说实话的人的编号,编号从1~N。

题解:二分图的最大匹配 匈牙利算法 模板题

贪心只能得到人数,不能得到字典序最大的方案…(贪心的方法:一个一个人来,每次把它放在他说的排名的第一个,如果要放的位置有人,看这个位置的人和我手上的那个人的Bi谁大,把大的拿在手上往后找,重复这样)

所以我们要用二分图最大匹配来搞,可以在kuangbin菊苣这里学习:http://www.cnblogs.com/kuangbin/archive/2012/08/26/2657446.html

由于这题数据有点碉,不能用邻接矩阵,用邻接表比较好。(话说数组实现的邻接表好像叫超碉的链式前向星,我怕了)

代码:

 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usll unsigned ll
#define mz(array) memset(array, 0, sizeof(array))
#define mf1(array) memset(array, -1, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define FORD(i,x,n) for(i=(x);i>=(n);i--)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("1biao.out","w",stdout)
#define mp make_pair
#define pb push_back int N;
int a[],b[];
vector<int>v; const int maxu=;//左点数
const int maxv=;//右点数
const int maxm=maxu*maxv;//边数
struct vnode {
int v,next;
int cap;
};
int cnt,head[maxu];
vnode e[maxm]; inline void add(const int &x,const int &y,const int &z) {
e[cnt].v=y;
e[cnt].cap=z;
e[cnt].next=head[x];
head[x]=cnt;
cnt++;
} int uN,vN;
int linker[maxv];
bool used[maxv]; bool dfs(int u) { //从左边开始找增广路径
int v;
for(v=head[u]; v!=-; v=e[v].next) {
if(!used[e[v].v]) {
used[e[v].v]=true;
if(linker[e[v].v]==-||dfs(linker[e[v].v])) {
linker[e[v].v]=u;
return true;
}
}
}
return false;//这个不要忘了,经常忘记这句
} inline void farm() {
int res=;
int u;
int i,j;
memset(head,-,sizeof(head));
cnt=;
vN=;
uN=N;
FOR(i,,uN)
FOR(j,a[i],b[i])
add(i,j,);
mf1(linker);
for(u=uN; u>=; u--) {
memset(used,,sizeof(used));
if(dfs(u)) res++;
}
for(i=; i<=vN; i++) {
if(linker[i]!=-) v.pb(linker[i]);
}
return;
} int main() {
int T;
int i;
scanf("%d",&T);
while(T--) {
scanf("%d",&N);
v.clear();
FOR(i,,N) {
scanf("%d%d",&a[i],&b[i]);
}
farm();
sort(v.begin(),v.end());
int maxi=v.size();
printf("%d\n",maxi);
if(maxi>)printf("%d",v[]);
FOR(i,,maxi-) printf(" %d",v[i]);
puts("");
}
return ;
}

这题是我乱入别的学校在vjudge的训练看到的……过的人最多的题,然后我过不了!尿了,然后发现好像是专题比赛,怕了……

hdu3729 I'm Telling the Truth (二分图的最大匹配)的更多相关文章

  1. I'm Telling the Truth(二分图)

    .I'm Telling the Truth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...

  2. UVALive 5033 I'm Telling the Truth 二分图最大匹配(略有修改)

    I - I'm Telling the Truth Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu ...

  3. HDU3729 I'm Telling the Truth(字典序最大的最大流)

    题目大概说n个学生,都各自有一个互不相同的成绩排名,他们各自说了他们成绩排名所在区间,问最多有几个学生没说谎以及字典序最大的没说谎的学生序列. 学生作为一个X部的点,排名作为Y部的点,学生与其成绩排名 ...

  4. HDU-3729 I'm Telling the Truth

    一个点集是学生,一个点集是排名.然后通过学生的排名范围连线,求此二分图的最大匹配. 本题还要求是最大字典序输出,那么由贪心可得,你让标号从大到小找增广边就行了. #include <cstdli ...

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

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

  6. 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 ( ...

  7. POJ 2584 T-Shirt Gumbo (二分图多重最大匹配)

    题意 现在要将5种型号的衣服分发给n个参赛者,然后给出每个参赛者所需要的衣服的尺码的大小范围,在该尺码范围内的衣服该选手可以接受,再给出这5种型号衣服各自的数量,问是否存在一种分配方案使得每个选手都能 ...

  8. HDU 2444 The Accomodation of Students(二分图判定+最大匹配)

    这是一个基础的二分图,题意比较好理解,给出n个人,其中有m对互不了解的人,先让我们判断能不能把这n对分成两部分,这就用到的二分图的判断方法了,二分图是没有由奇数条边构成环的图,这里用bfs染色法就可以 ...

  9. 二分图的最大匹配——最大流EK算法

    序: 既然是个图,并且求边数的最大值.那么这就可以转化为网络流的求最大流问题. 只需要将源点与其中一子集的所有节点相连,汇点与另一子集的所有节点相连,将所有弧的流量限制置为1,那么最大流 == 最大匹 ...

随机推荐

  1. 【bzoj3611】 大工程

    http://www.lydsy.com/JudgeOnline/problem.php?id=3611 (题目链接) 搞了1天= =,感觉人都变蠢了... 题意 给出一个n个节点的树,每条边边权为1 ...

  2. Linq Like

    Like的操作,有点像in,但是,方向变了.什么意思呢.就是你给定一个字符串,去寻找数据中某个字段包含这个字符串.就是给定的字符串是某字段的子集.Sql Script是这么写的. Selec * fr ...

  3. CCTray配置如何添加远程服务器

    前提: Windows防火墙必须开通的TCP端口 或者直接把防火墙关闭(不建议) 或者直接在防火墙规则增加CCNET的服务进去 总者,只要确保能telnet ip 21234能通即可 建议全部软件都装 ...

  4. CSS基础知识真难啊-position-relative-absolute

    http://blog.csdn.net/libertea/article/details/11662661 -----------position:relative:生成相对定位的元素,相对于其正常 ...

  5. Android中运行的错误:java.lang.UnsatisfiedLinkError: Couldn't load locSDK3: findLibrary returned null.

    ---恢复内容开始--- 明明已经加入了liblocSDK3.so,但总是无法定位.提示错误java.lang.UnsatisfiedLinkError: Couldn't load locSDK3: ...

  6. CF 84D Doctor(二分)

    题目链接: 传送门 Doctor time limit per test:1 second     memory limit per test:256 megabytes Description Th ...

  7. 【Alpha版本】 第八天 11.16

    一.站立式会议照片: 二.项目燃尽图: 三.项目进展: 成 员 昨天完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 完成我要应聘的列表显示,完成账户信息设置界面 完成我要应聘的详情显 ...

  8. python3,交互模式,无法使用ctrl和方向键,需要和ctrl一块用

    转自csdn博客 http://blog.csdn.net/pumaadamsjack/article/details/52447989 https://pypi.python.org/pypi/re ...

  9. Python 培训之正则表达式

    re 模块 re.math 从头匹配 re.search 结构: re.math(r'^c',a)   不符合返回None 原字符: . 任意字符 [ ] 或者 [A-Z,a-z,b] \d 数字 \ ...

  10. 最短路径(Floyd)算法

    #include <stdio.h>#include <stdlib.h>/* Floyd算法 */#define VNUM 5#define MV 65536int P[VN ...