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. 【BZOJ-4326】运输计划 树链剖分 + 树上差分 + 二分

    4326: NOIP2015 运输计划 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 703  Solved: 461[Submit][Status] ...

  2. 【BZOJ-4568】幸运数字 树链剖分 + 线性基合并

    4568: [Scoi2016]幸运数字 Time Limit: 60 Sec  Memory Limit: 256 MBSubmit: 238  Solved: 113[Submit][Status ...

  3. “SQLServerAgent当前未运行”问题解决

    在执行SQLServer计划任务的时候,出现了如下所示的错误: 解决方法: 配置工具--sqlserver 配置管理器--SQLSERVER服务--右侧最下面--点击启动AGENT即可

  4. 【Phylab2.0】Alpha版本测试报告

    测试报告集 点击链接

  5. 【Alpha阶段】第六次Scrum例会

    会议信息 时间:2016.10.27 21:30 时长:30min 地点:大运村1号公寓5楼楼道 类型:日常Scrum会议 个人任务报告 姓名 今日已完成Issue 明日计划Issue 工作困难 今日 ...

  6. Linux学习一周初体验

    Linux一周初体验一.准备工欲善其事,必先利其器--虚拟机+Redhat7.0构成学习的环境.安装有条不紊.按部就班.......(涉及到的KVM.VNC.Root密码重置等内容,之后再详细了解)注 ...

  7. javascript变量、作用域和内存问题......

    1基本类型是指那些保存在栈内存的简单数据段,引用类型是指那些保存在堆内存中的对象,变量中保存的实际上只是一个指针. 2javascript中5种基本数据类型Undefined,Null,Boolean ...

  8. python学习笔记-(三)条件判断和循环

    1.条件判断语句 Python中条件选择语句的关键字为:if .elif .else这三个.其基本形式如下: age_of_cc = 27 age = int(input("guessage ...

  9. ASP------如何读取文件内容

    <body> @{ var dataFile = Server.MapPath("~/App_Data/Persons.txt"); Array list = File ...

  10. 天行API服务器地址申请

    http://www.tianapi.com/ http://www.huceo.com/post/383.html