HDU-3729 I'm Telling the Truth
一个点集是学生,一个点集是排名。然后通过学生的排名范围连线,求此二分图的最大匹配。
本题还要求是最大字典序输出,那么由贪心可得,你让标号从大到小找增广边就行了。
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <fstream>
#include <iostream> #define rep(i, l, r) for(int i=l; i<=r; i++)
#define down(i, l, r) for(int i=l; i>=r; i--)
#define N 69
#define M 100009 using namespace std;
int read()
{
int x=0, f=1; char ch=getchar();
while (ch<'0' || ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
while (ch>='0' && ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
return x*f;
} int n, l[N], r[N], k[M], b[M], ans, ansk[N], s; bool Find(int x)
{
rep(i, l[x], r[x]) if (b[i]!=s)
{
b[i]=s; if (!k[i] || Find(k[i])) { k[i]=x; return true; }
}
return false;
} int main()
{
int t=read(); while (t--)
{
n=read();
rep(i, 1, n) l[i]=read(), r[i]=read();
rep(i, 1, M-1) k[i]=b[i]=0;
rep(i, 1, n) ansk[i]=0; ans=0;
down(i, n, 1) if (Find(s=i)) ans++, ansk[i]=1;
printf("%d\n", ans);
rep(i, 1, n) if (ansk[i]) { if (--ans) printf("%d ", i); else printf("%d\n", i); }
}
return 0;
}
HDU-3729 I'm Telling the Truth的更多相关文章
- 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 ( ...
- hdu 3729 I'm Telling the Truth 二分图匹配
裸的二分图匹配.需要输出方案. #include<cstdio> #include<cstring> #include<vector> #include<al ...
- HDU 3729 I'm Telling the Truth (二分匹配)
题意:给定 n 个人成绩排名区间,然后问你最多有多少人成绩是真实的. 析:真是没想到二分匹配,....后来看到,一下子就明白了,原来是水题,二分匹配,只要把每个人和他对应的区间连起来就好,跑一次二分匹 ...
- HDU - 3729 I'm Telling the Truth(二分匹配)
题意:有n个人,每个人给出自己的名次区间,问最多有多少个人没撒谎,如果有多解,输出字典序最大的解. 分析: 1.因为字典序最大,所以从后往前分析. 2.假设后面的人没说谎,并将此作为已知条件,然后从后 ...
- 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/ ...
- HDU 3729 I'm Telling the Truth(二部图最大匹配+结果输出)
职务地址:HDU 3729 二分图最大匹配+按字典序输出结果. 仅仅要从数字大的開始匹配就能够保证字典序最大了.群里有人问. . 就顺手写了这题. . 代码例如以下: #include <ios ...
- UVALive 5033 I'm Telling the Truth 二分图最大匹配(略有修改)
I - I'm Telling the Truth Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu ...
- I'm Telling the Truth(二分图)
.I'm Telling the Truth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 3729(二分图最大匹配)
I'm Telling the Truth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 【I'm Telling the Truth】【HDU - 3729】 【匈牙利算法,DFS】
思路 题意:该题主要说几个同学分别说出自己的名次所处区间,最后输出可能存在的未说谎的人数及对应的学生编号,而且要求字典序最大. 思路:刚刚接触匈牙利算法,了解的还不太清楚,附一个专门讲解匈牙利算法的博 ...
随机推荐
- MovieReview—Wile Hunter(荒野猎人)
Faith is Power Faith is power, this sentence is not wrong. Find your own beliefs, and strug ...
- JAVA小游戏之两个物体碰撞产生的碰撞检测
首先必须了解两个物体,在移动时,会有怎样的效果,比如沪我们小时候耍过的坦克大战.看起来很简单,但是写起代码来,复杂的要多: 下面举个例子: // 构造一个新的 Rectangle,其左上角的坐标为 ( ...
- A winner is a dreamer who never gives up
A winner is a dreamer who never gives up. 成功者是坚持梦想不放弃的人.(Nelson Mandela)
- js引入的数组 会被页面缓存,如需要被强制性不缓存,请用function return 就ok了
js引入的数组 会被页面缓存,如需要被强制性不缓存,请用function return 就ok了
- momentum公式
momentum对于w的更新公式: http://caffe.berkeleyvision.org/tutorial/solver.html
- javaweb基础(17)_jsp九个内置对象
一.JSP运行原理 每个JSP 页面在第一次被访问时,WEB容器都会把请求交给JSP引擎(即一个Java程序)去处理.JSP引擎先将JSP翻译成一个_jspServlet(实质上也是一个servlet ...
- Service Unavailable HTTP Error 503. The service is unavailable.
原因: public void SetCurrentType(string[] projTypes) { _ProjTypes = _ProjTypes; } 确保没有无限递归或无限循环
- 【转】嵌入式操作系统VxWorks中TFFS文件系统的构建
时间:2005-02-20 来源:21IC中国电子网 作者:771所加固机工程部 蔡本华 高文炜 关键字:VxWorks TFFS 嵌入式操作系统 文件系统 摘要:目前的嵌入式 ...
- Spring Security 与 OAuth2(介绍)
https://www.jianshu.com/p/68f22f9a00ee Spring Security 与 OAuth2(介绍) 林塬 2018.01.23 11:14* 字数 3097 阅读 ...
- sql规范
(一) 建表规约 -------------- 1. [强制]表达是与否概念的字段,必须使用is_xxx的方式命名,数据类型是unsigned tinyint( 1表示是,0表示否). > 说明 ...