题意:有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(二分匹配)的更多相关文章

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

  2. HDU 3729 I'm Telling the Truth (二分匹配)

    题意:给定 n 个人成绩排名区间,然后问你最多有多少人成绩是真实的. 析:真是没想到二分匹配,....后来看到,一下子就明白了,原来是水题,二分匹配,只要把每个人和他对应的区间连起来就好,跑一次二分匹 ...

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

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

  4. HDU 2236:无题II(二分搜索+二分匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=2236 题意:中文题意. 思路:先找出最大和最小值,然后二分差值,对于每一个差值从下界开始枚举判断能不能二分匹配. ...

  5. 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 ...

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

  7. 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/ ...

  8. HDU 2063 过山车(二分匹配入门)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...

  9. HDU 3729 I&#39;m Telling the Truth(二部图最大匹配+结果输出)

    职务地址:HDU 3729 二分图最大匹配+按字典序输出结果. 仅仅要从数字大的開始匹配就能够保证字典序最大了.群里有人问. . 就顺手写了这题. . 代码例如以下: #include <ios ...

随机推荐

  1. JavaScript一个简单的图片切换布局

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. 128、Java面向对象之对象的比较

    01.代码如下: package TIANPAN; class Book { private String title; private double price; public Book(Strin ...

  3. Lesson 11 How to grow old

    What, accoroding to the author is the best way to overcome the fear of death as you get older? Some ...

  4. GPU运行Tensorflow的几点建议

    1.在运行之前先查看GPU的使用情况: 指令:nvidia-smi 备注:查看GPU此时的使用情况 或者 指令:watch nvidia-smi 备注:实时返回GPU使用情况 2.指定GPU训练: 方 ...

  5. java、mysql、oracle、pgsql数据类型对应关系

    看不清 请 Ctrl+鼠标滚轮     放大页面

  6. 搭建solr集群的时候出现 ./zkcli.sh:行13: unzip: 未找到命令

    主要的原因是: linux系统下面没有安装压缩解压工具    zip 和 unzip:需要我们自己手动的安装: 利用yum命令安装即可: yum install -y unzip zip

  7. springboot打war包上传到阿里云的Linux服务器

    下面的每一步应该都必不可少: 1.启动类 继承这个类,并且重新configure这个方法,return builder.sources(Code007Application.class); 2.pom ...

  8. 六种方式实现hibernate查询,及IDE推荐

      这些天过的好乱,也许是因为考完试了,心里有些松懈吧.也许是最近发生的事对我有些触动吧.感觉自己都已经不懂自己了.面对一些人的教导,我很感激.因为很多话都对我有非常大的帮助和启发,也让我除了做技术, ...

  9. ReadyBoost 的应用教程

    一.什么是ReadyBoost 根据百度百科介绍,ReadyBoost是存在于Windows Vista中的一项新技术,在继Vista的下一代操作系统Windows 7中,同样包 含着这项技术,它利用 ...

  10. SciPy 统计

    章节 SciPy 介绍 SciPy 安装 SciPy 基础功能 SciPy 特殊函数 SciPy k均值聚类 SciPy 常量 SciPy fftpack(傅里叶变换) SciPy 积分 SciPy ...