HDU 3729 I'm Telling the Truth (二分匹配)
题意:给定 n 个人成绩排名区间,然后问你最多有多少人成绩是真实的。
析:真是没想到二分匹配,。。。。后来看到,一下子就明白了,原来是水题,二分匹配,只要把每个人和他对应的区间连起来就好,跑一次二分匹配,裸的。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 101000 + 10;
const int mod = 10;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r > 0 && r <= n && c > 0 && c <= m;
} vector<int> G[maxn]; void add(int u, int v){
G[u].push_back(v);
G[v].push_back(u);
} int match[maxn];
bool vis[maxn]; bool dfs(int u){
vis[u] = true;
for(int i = 0; i < G[u].size(); ++i){
int v = G[u][i];
int w = match[v];
if(w == -1 || !vis[w] && dfs(w)){
match[u] = v;
match[v] = u;
return true;
}
}
return false;
} int main(){
int T; cin >> T;
while(T--){
scanf("%d", &n);
for(int i = 0; i < maxn; ++i) G[i].clear();
for(int i = 0; i < n; ++i){
int u, v;
scanf("%d %d", &u, &v);
for(int j = u+100; j <= v+100; ++j)
add(i, j);
} memset(match, -1, sizeof match);
int ans = 0;
for(int i = n-1; i >= 0; --i) if(match[i] < 0){
memset(vis, 0, sizeof vis);
if(dfs(i)) ++ans;
}
printf("%d\n", ans);
int cnt = 0;
for(int i = 0; i < n; ++i)
if(match[i] != -1) printf("%d%c", i+1, ++cnt == ans ? '\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 二分图匹配
裸的二分图匹配.需要输出方案. #include<cstdio> #include<cstring> #include<vector> #include<al ...
- HDU - 3729 I'm Telling the Truth(二分匹配)
题意:有n个人,每个人给出自己的名次区间,问最多有多少个人没撒谎,如果有多解,输出字典序最大的解. 分析: 1.因为字典序最大,所以从后往前分析. 2.假设后面的人没说谎,并将此作为已知条件,然后从后 ...
- 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 ...
随机推荐
- NPOI时间格式判断
switch (cell.CellType) { case CellType.BLANK: //空数据类型处理 dr[iRow] = ""; break; case CellTyp ...
- ArcGIS_Lisence安装步骤
1.双击lisence.exe文件 2.下一步 3.关闭 4.下一步 5.下一步 6.下一步 7.安装 8.完成 9.OK
- 为什么新生代内存需要有两个Survivor区?
对于常见的GC算法,我们都应该知道,例如:标记清除算法.复制算法.标记整理算法等.标记清除算法由于回收之后存在大量的内存碎片,存在效率和空间问题!为了解决效率问题,引出了复制算法!熟悉GC算法的小伙伴 ...
- AbstractIdleService
该类有一个startup和shutdown方法,启动此服务或者结束此服务的时候可以调用. Runtime.getRuntime().addShutdownHook(new Thread() {@Ove ...
- Angular4中利用promise异步加载gojs
GoJS是一个实现交互类图表(比如流程图,树图,关系图,力导图等等)的JS库 gojs提供了angular的基本例子,不过是离线版 https://github.com/NorthwoodsSoftw ...
- flask系列四之SQLAlchemy
一.SQLAlchemy简介 (1)flask_sqlalchemy是一套ORM框架. (2)ORM(Object Relationship Mapping):模型关系映射 (3)ORM的好处:可以让 ...
- javascript中的类方法、构造方法、原型方法的对比
如果你已经接触js很久了,那么应该可以看看我总结的是否正确,如果你刚开始学习,那么通过我的总结,你可以更快的区别他们,记得我刚接触js时,这一块反正是模糊了很久! 1,长相的区别: function ...
- 使用Statement接口实现增,删,改操作(工作中不常用这个,而用PreparedStatement接口)
一.Statement接口 作用:用于执行静态 SQL 语句并返回它所生成结果的对象. 1. 创建数据库连接类及相册实体,代码如下: package com.learn.jdbc.util; impo ...
- 20-从零玩转JavaWeb-Super关键字与子类初始化过程
配套详解视频 super关键字 继承内存分析 this与super对比 继承字段隐藏 继承Object根类 一.Super关键字的作用 this:当前对象,谁调用this所在的方法,this就是哪一 ...
- Python函数定义及传参方式
主要内容: 1.函数初识 2.函数传参方式 (1)位置参数 (2)默认参数 (3)关键参数 (4)非固定传参 一.函数初识 1. ...