URAL-1997 Those are not the droids you're looking for 二分匹配
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1997
题意:记录了n个人进出门的时间点,每个人在房子里面待的时间要么小于等于a,要么大于等于b,询问能否对进出门的时间点找到一个合适的匹配。
对于满足的要求建立边即可,然后看是否能找到最大匹配。
//STATUS:C++_AC_109MS_4361KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int vis[N],y[N],w[N][N],t[N][],id[N],l[N],r[N];
int n,a,b,cnt1,cnt2; int dfs(int u)
{
int v;
for(v=;v<cnt1;v++){
if(vis[v] || !w[u][v])continue;
vis[v]=;
if(y[v]==- || dfs(y[v])){
y[v]=u;
return ;
}
}
return ;
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,L,R,ok;
while(~scanf("%d%d",&a,&b))
{
L=b+,R=a-;
scanf("%d",&n);
cnt1=cnt2=;
for(i=;i<n;i++){
scanf("%d%d",&t[i][],&t[i][]);
if(t[i][]){
l[cnt1]=i;
id[i]=cnt1++;
}
else {
r[cnt2]=i;
id[i]=cnt2++;
}
}
mem(w,);
for(i=;i<n;i++){
if(t[i][]==)continue;
for(j=i-;j>=;j--){
if(t[j][]==)continue;
if(t[i][]-t[j][]>=L && t[i][]-t[j][]<=R)continue;
w[id[i]][id[j]]=;
}
}
mem(y,-);ok=;
for(i=;i<cnt1;i++){
mem(vis,);
if(dfs(i)==){
ok=;
break;
}
} if(ok){
printf("No reason\n");
for(i=;i<cnt1;i++){
printf("%d %d\n",t[r[i]][],t[ l[ y[i] ] ][]);
}
}
else printf("Liar\n"); }
return ;
}
URAL-1997 Those are not the droids you're looking for 二分匹配的更多相关文章
- Timus OJ 1997 Those are not the droids you're looking for (二分匹配)
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1997 这个星球上有两种人,一种进酒吧至少玩a小时,另一种进酒吧最多玩b小时. 下面n行是 ...
- URAL 1997 Those are not the droids you're looking for 二分图最大匹配
Those are not the droids you're looking for 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1 ...
- URAL 1997 Those are not the droids you're looking for
二分图的最大匹配. 每一个$0$与$1$配对,只建立满足时差大于等于$a$或者小于等于$b$的边,如果二分图最大匹配等于$n/2$,那么有解,遍历每一条边输出答案,否则无解. #include< ...
- 转债---Pregel: A System for Large-Scale Graph Processing(译)
转载:http://duanple.blog.163.com/blog/static/70971767201281610126277/ 作者:Grzegorz Malewicz, Matthew ...
- 二分图水一波~~~~d带你飞
Current Time: 2016-03-11 17:45:36 Contest Type: Public Start Time: 2016-03-04 13:00:00 Contest Statu ...
- [kuangbin带你飞]专题十 匹配问题
A-L 二分匹配 M-O 二分图多重匹配 P-Q 二分图最大权匹配 R-S 一般图匹配带花树 模板请自己找 ID Origin Title 61 / 72 Problem A HD ...
- Pregel: A System for Large-Scale Graph Processing(译)
[说明:Pregel这篇是发表在2010年的SIGMOD上,Pregel这个名称是为了纪念欧拉,在他提出的格尼斯堡七桥问题中,那些桥所在的河就叫Pregel.最初是为了解决PageRank计算问题,由 ...
- HDU分类
原地址:http://www.byywee.com/page/M0/S607/607452.html 总结了一下ACM STEPS的各章内容,趁便附上我的Steps题号(每人的不一样). 别的,此文首 ...
- [二分匹配]URAL1721Two Sides of the Same Coin
题意:给n个人,每个人都有3个参数,分别是名字,能做的事(a:statements b:testdate a.b都可以:anything),Rank 要求:一个人只能做一个事件,要两个人Rank相 ...
随机推荐
- Volley HTTP库系列教程(3)自定义RequestQueue和编写单例RequestQueue示例
Setting Up a RequestQueue Previous Next This lesson teaches you to Set Up a Network and Cache Use a ...
- 编写类String的构造函数、析构函数和赋值函数
已知类String的原型为: class String { public: String(const char *str = NULL); // 普通构造函数 String(const Str ...
- 【Todo】深入PHP内核系列
看到一个<深入PHP内核>系列,Todo: http://www.csdn.net/article/2014-09-15/2821685-exploring-of-the-php [问底] ...
- Git基础(一)
本系列内容主要介绍Git一些基本的也是最常用的命令,相信读完本系列内容后,你也差不多能够上手Git了.读完本系列,你就能初始化一个新的代码仓库,做一些适当配置:开始或停止跟踪某些文件:暂存或提交某些更 ...
- Jquery Highcharts 参数配置说明
chart: renderTo 图表的页面显示容器 defaultSeriesType 图表的显示类型(line,spline, scatter, splinearea bar,pie,area,co ...
- HDU 1847 (博弈 找规律) Good Luck in CET-4 Everybody!
为了提高题解质量还是简单证明一下:3的倍数是必败状态. 如果n % 3 = 1,那么拿走1个石子:如果n % 3 = 2,那么拿走两个石子,都将转移到3的倍数的状态.所以每个必胜状态都有一个后继是必败 ...
- python执行mysqldump命令
本文简单讲述如何利用python执行一些sql语句,例如执行mysqldump命令,进行数据库备份,备份成sql文件 #!/usr/bin/python#导入os模块import os#导入时间模块i ...
- Java 动态写轮眼 SharinganJPanel (整理)
/** * Java 动态写轮眼 SharingganJPanel (整理) * * 2016-1-2 深圳 南山平山村 曾剑锋 * 设计声明: * 1.虽然岸本是日本人,而我个人作为其模仿者,依 ...
- NBUT 1122 Shameimaru's Candid Camera(水)
题意: 给n*m个格子,初始时每个格子中有个数值为0,部分格子中含有炸弹,每个炸弹爆炸可以将周围的8个非炸弹格子中的数值加1,求全部炸弹炸完后那些非0且非炸弹格子中的数是多少. 思路: 另开一个矩阵, ...
- jq的post传递数组
a = new Object(); b = new Object(); a['你好[眼见]'] = "y"; a[ ...