题目链接: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 二分匹配的更多相关文章

  1. 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行是 ...

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

  3. URAL 1997 Those are not the droids you're looking for

    二分图的最大匹配. 每一个$0$与$1$配对,只建立满足时差大于等于$a$或者小于等于$b$的边,如果二分图最大匹配等于$n/2$,那么有解,遍历每一条边输出答案,否则无解. #include< ...

  4. 转债---Pregel: A System for Large-Scale Graph Processing(译)

    转载:http://duanple.blog.163.com/blog/static/70971767201281610126277/   作者:Grzegorz Malewicz, Matthew ...

  5. 二分图水一波~~~~d带你飞

    Current Time: 2016-03-11 17:45:36 Contest Type: Public Start Time: 2016-03-04 13:00:00 Contest Statu ...

  6. [kuangbin带你飞]专题十 匹配问题

        A-L 二分匹配 M-O 二分图多重匹配 P-Q 二分图最大权匹配 R-S 一般图匹配带花树 模板请自己找     ID Origin Title   61 / 72 Problem A HD ...

  7. Pregel: A System for Large-Scale Graph Processing(译)

    [说明:Pregel这篇是发表在2010年的SIGMOD上,Pregel这个名称是为了纪念欧拉,在他提出的格尼斯堡七桥问题中,那些桥所在的河就叫Pregel.最初是为了解决PageRank计算问题,由 ...

  8. HDU分类

    原地址:http://www.byywee.com/page/M0/S607/607452.html 总结了一下ACM STEPS的各章内容,趁便附上我的Steps题号(每人的不一样). 别的,此文首 ...

  9. [二分匹配]URAL1721Two Sides of the Same Coin

    题意:给n个人,每个人都有3个参数,分别是名字,能做的事(a:statements  b:testdate  a.b都可以:anything),Rank 要求:一个人只能做一个事件,要两个人Rank相 ...

随机推荐

  1. Gliffy Diagrams 好用的流程图工具

    很好用!加上百度脑图!good!

  2. 菜鸟学习笔记2,$(document).ready()使用讨论

    $(document).ready()使用讨论 $(document).ready()  一.先为说说 $(document).ready() 的功能: 1. JQuery API对 $(docume ...

  3. Java 图片提取RGB数组 RGBOfCharMaps (整理)

    package demo; /** * Java 图片提取RGB数组 RGBOfCharMaps (整理) * 声明: * 和ImageCombining配合使用的工具,这里是提取图片的R.G.B生成 ...

  4. php 获取指定日期所在月份的最后一天

    本文引用来自 http://hi.baidu.com/yflife/item/fd00ef142c5967fcdceeca84 php 获取指定月最后一天: <?phpfunction gett ...

  5. T-SQL备忘(3):分组合并

    --CREATE TABLE test(code varchar(50), [name] varchar(10),[count] int ) --INSERT test SELECT '001' , ...

  6. 18个jQuery Mobile开发贴士和教程

    jQuery Mobile 是 jQuery 在手机上和平板设备上的版本.jQuery Mobile 不仅会给主流移动平台带来jQuery核心库,而且会发布一个完整统一的jQuery移动UI框架.支持 ...

  7. 关于jdbc收集

    一.如果我这样获得一个resultset ResultSet rs=statment.execquery("select * from tab"我如何能够从resultset中获得 ...

  8. C++中类的public,private,protected比较

    当private,public,protected单纯的作为一个类中的成员权限设置时:private: 只能由该类中的函数.其友元函数访问,不能被任何其他访问,该类的对象也不能访问. protecte ...

  9. 【Leetcode】Reorder List JAVA

    一.题目描述 Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must ...

  10. PyPI镜像网站

    镜像列表:http://www.pypi-mirrors.org/ 清华镜像:http://e.pypi.python.org/