hdu3729 I'm Telling the Truth (二分图的最大匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=3729
I'm Telling the TruthTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 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 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 (二分图的最大匹配)的更多相关文章
- I'm Telling the Truth(二分图)
.I'm Telling the Truth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- UVALive 5033 I'm Telling the Truth 二分图最大匹配(略有修改)
I - I'm Telling the Truth Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu ...
- HDU3729 I'm Telling the Truth(字典序最大的最大流)
题目大概说n个学生,都各自有一个互不相同的成绩排名,他们各自说了他们成绩排名所在区间,问最多有几个学生没说谎以及字典序最大的没说谎的学生序列. 学生作为一个X部的点,排名作为Y部的点,学生与其成绩排名 ...
- HDU-3729 I'm Telling the Truth
一个点集是学生,一个点集是排名.然后通过学生的排名范围连线,求此二分图的最大匹配. 本题还要求是最大字典序输出,那么由贪心可得,你让标号从大到小找增广边就行了. #include <cstdli ...
- hdu 3729 I'm Telling the Truth 二分图匹配
裸的二分图匹配.需要输出方案. #include<cstdio> #include<cstring> #include<vector> #include<al ...
- 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 ( ...
- POJ 2584 T-Shirt Gumbo (二分图多重最大匹配)
题意 现在要将5种型号的衣服分发给n个参赛者,然后给出每个参赛者所需要的衣服的尺码的大小范围,在该尺码范围内的衣服该选手可以接受,再给出这5种型号衣服各自的数量,问是否存在一种分配方案使得每个选手都能 ...
- HDU 2444 The Accomodation of Students(二分图判定+最大匹配)
这是一个基础的二分图,题意比较好理解,给出n个人,其中有m对互不了解的人,先让我们判断能不能把这n对分成两部分,这就用到的二分图的判断方法了,二分图是没有由奇数条边构成环的图,这里用bfs染色法就可以 ...
- 二分图的最大匹配——最大流EK算法
序: 既然是个图,并且求边数的最大值.那么这就可以转化为网络流的求最大流问题. 只需要将源点与其中一子集的所有节点相连,汇点与另一子集的所有节点相连,将所有弧的流量限制置为1,那么最大流 == 最大匹 ...
随机推荐
- 【BZOJ-3784】树上的路径 点分治 + ST + 堆
3784: 树上的路径 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 462 Solved: 153[Submit][Status][Discuss ...
- 【BZOJ-1670】Building the Moat护城河的挖掘 Graham扫描法 + 凸包
1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 464 Solv ...
- Jenkins用HTTP Request Plugin插件进行网站的监控(运维监控)
使用的插件: [HTTP Request Plugin] 思路: 说明:只能是网站是否正常打开,而不能是这个网站业务是否正常,如果是后者,则需要写特定的接口进行请求处理. 1.通过插件,发送GET请求 ...
- [NOIP2015] 提高组 洛谷P2615 神奇的幻方
题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...
- Deformity JSP Webshell、Webshell Hidden Learning
catalogue . JSP基础语法 . JSP Lexer By Lua . Open Source Code Analyzers in Java . WEBSHELL Samples . she ...
- [IOS 静态库]
http://www.2cto.com/kf/201402/276718.html 一.什么是库? 库是共享程序代码的方式,一般分为静态库和动态库. 二.静态库与动态库的区别? 静态库:链接时完整地拷 ...
- Linux上性能异常定位以及性能监控
引言:大多数的服务都是跑在Linux上的,Linux现在也已经到了一个很广泛的应用,但是仍然会有很多问题出现,我们就来讨论下我们性能监控的指标,性能监控无非就是从I/O,内存,CPU,TCP连接数,网 ...
- php 读取excel表格中的内容
<?php /** * excel表格内容在网页中显示 * * 首先需要下载PHPExcel 工具包 * 网址: http://phpexcel.codeplex.com/releases/vi ...
- JavaWeb---总结(六)Servlet开发(一)
一.Servlet简介 Servlet是sun公司提供的一门用于开发动态web资源的技术. Sun公司在其API中提供了一个servlet接口,用户若想用发一个动态web资源(即开发一个Java程序向 ...
- 基于WS-BPEL2.0的服务组合研究
http://tech.it168.com/soadocument/2008-01-03/200801031332376.shtml WS-BPEL是为组合Web服务而制定的一项规范.它的前身是由IB ...