HDU - 3729 I'm Telling the Truth(二分匹配)
题意:有n个人,每个人给出自己的名次区间,问最多有多少个人没撒谎,如果有多解,输出字典序最大的解。
分析:
1、因为字典序最大,所以从后往前分析。
2、假设后面的人没说谎,并将此作为已知条件,然后从后往前依次给每个人找到合适的名次,输出所有能找到合适名次的人即可。
3、假定给第i个人安排名次,第i+1~n个人名次已经安排好,假如第i个人想占的名次被第j个人所占,那就从第j个人可以占的名次中再找个合适的名次给j,然后把空出来的这个名次给i,如果i可以占的所有名次都被占且占领的人找不到其他可以占的名次,则i找不到合适的名次。
4、总而言之,从后往前,依次给每个人匹配一个名次,若匹配不到(出现矛盾),则该人说谎。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 10;
const double pi = acos(-1.0);
const int MAXN = 60 + 10;
const int MAXT = 100000 + 10;
using namespace std;
bool used[MAXT];
int match[MAXT];
int n;
vector<int> ans;
struct Node{
int l, r;
void read(){
scanf("%d%d", &l, &r);
}
}num[MAXN];
bool dfs(int x){
for(int i = num[x].l; i <= num[x].r; ++i){
if(!used[i]){
used[i] = true;
if(match[i] == -1 || dfs(match[i])){
match[i] = x;
return true;
}
}
}
return false;
}
void hungary(){
for(int i = n; i >= 1; --i){
memset(used, false, sizeof used);
if(dfs(i)) ans.push_back(i);
}
}
int main(){
int T;
scanf("%d", &T);
while(T--){
ans.clear();
memset(match, -1, sizeof match);
scanf("%d", &n);
for(int i = 1; i <= n; ++i){
num[i].read();
}
hungary();
int len = ans.size();
printf("%d\n", len);
for(int i = len - 1; i >= 0; --i){
if(i != len - 1) printf(" ");
printf("%d", ans[i]);
}
printf("\n");
}
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 (二分匹配)
题意:给定 n 个人成绩排名区间,然后问你最多有多少人成绩是真实的. 析:真是没想到二分匹配,....后来看到,一下子就明白了,原来是水题,二分匹配,只要把每个人和他对应的区间连起来就好,跑一次二分匹 ...
- hdu 3729 I'm Telling the Truth 二分图匹配
裸的二分图匹配.需要输出方案. #include<cstdio> #include<cstring> #include<vector> #include<al ...
- HDU 2236:无题II(二分搜索+二分匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=2236 题意:中文题意. 思路:先找出最大和最小值,然后二分差值,对于每一个差值从下界开始枚举判断能不能二分匹配. ...
- hdu 1498 50 years, 50 colors(二分匹配_匈牙利算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1498 50 years, 50 colors Time Limit: 2000/1000 MS (Ja ...
- HDU 2389 Rain on your Parade(二分匹配,Hopcroft-Carp算法)
Rain on your Parade Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K (Java/Ot ...
- 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 2063 过山车(二分匹配入门)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...
- HDU 3729 I'm Telling the Truth(二部图最大匹配+结果输出)
职务地址:HDU 3729 二分图最大匹配+按字典序输出结果. 仅仅要从数字大的開始匹配就能够保证字典序最大了.群里有人问. . 就顺手写了这题. . 代码例如以下: #include <ios ...
随机推荐
- iOS 批量上传图片的 3 种方法
AFNetworking 在去年年底升级到了 3.0.这个版本更新想必有很多好处,然而让我吃惊的是,它并没有 batch request 接口.之前的 1.x 版本.2.x 版本都实现了这个很常见的需 ...
- 中山DAy2——普及
今天挺不友好的,早上忘记定闹钟,晚了半小时起床,然后早上信心满满打算弄他个300分.结果……132.2分·.WTF??? T1:disease 题意:有n头奶牛,k种细菌(k<=15),给你每头 ...
- vbs操作IE对象
Dim fso,filepath,i 'Dim ExcelBook,ExcelSheet,MyExcelBook,MyExcelSheet Dim ie Set ie=WScript.CreateOb ...
- BigDecimal类用于计算(不会丢失精度)
- 洛谷 P6046 [CTSC2000]快乐的蜜月
先讲解一下如何处理这道题的毒瘤输入.\(m\) 和 \(d\) 之间的"/"和" TO "都可以用 getchar() 强行吃掉,日期的转换可以用公式 \(s_ ...
- Centos7精简版安装常用扩展插件
一.安装ifconfig *确认本机是否真实存在ifconfig* echo $PATH 查看环境变量路径 ls /usr/sbin/ 查看此路径下是否有ifconfig这个程序 find / -na ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表格:精简表格
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- PDO 小知识
一.前言 PDO(PHP Data Object)提供了一个通用接口访问多种数据库,即抽象的数据模型支持连接多种数据库. PDO扩展为PHP定义了一个访问数据库的轻量.持久的接口.其本身并不能实现任何 ...
- ionic3记录之弹窗Alert
一个业务流程需要多个弹窗: 在上一个弹窗的onDidDissmiss写下一个弹窗:
- mysql设置timpstamp的默认值为 '0000-00-00 00:00:00' 时报错
问题:mysql设置timpstamp的默认值为 '0000-00-00 00:00:00' 时报错: ERROR 1067 (42000): Invalid default value for 'u ...