Those are not the droids you're looking for

题目连接:

http://acm.timus.ru/problem.aspx?space=1&num=1997

Description

Bar owner: Hey. We don’t serve their kind here.

Luke: What?

Bar owner: Your droids – they’ll have to wait outside. We don’t want them here.

Planet Tatooine is quite far from the center of the Galaxy. It is at the intersection of many hyperspace paths and it hosts smugglers and hoods of all sorts. The pilots who visited external territories have been to the space port bar called Mos Eisley for a drink at least once.

In this bar you can find a bunch of rascals and scoundrels from all over the Galaxy. The bar owner is ready to make drinks for any client except for, perhaps, a droid. Usually the bar has a lot of smugglers hanging out there. Each smuggler spends at least a minutes inside hoping to meet a good client. Cargo owners show up quite often as well. They usually find a dealer quickly, so they never spend more than b minutes in the bar.

The imperial stormtroopers are searching through Tatooine for the escaped droids. The bar owner said that no droids had ever been on his territory. He also said that nobody except for smugglers and cargo owners had been in the place recently.

Help the stormtroopers find out if the owner is a liar. For that, you are going to need the daily records from the sensor on the entrance door. The sensor keeps record of the time when somebody entered the bar or left it. The stormtroopers got the records after the bar had been closed, so there was nobody in the bar before or after the sensor took the records. You can assume that the sensor is working properly. That is, if somebody went through the bar door, the sensor made a record of that. You can also assume that the bar clients go in and out only through the door with the sensor. But the bar owner and the staff use the ‘staff only’ door.

Input

The first line of the input contains integers a and b (1 ≤ a, b ≤ 10 9, b + 1 < a). The second line contains integer n — the number of records from the sensor (2 ≤ n ≤ 1000). The i-th of the next n lines contains two integers ti and di (1 ≤ ti ≤ 10 9, di ∈ {0,1}) — the time of the i-th record and direction (0 — in the bar, 1 — out of the bar). The records in the input are listed in the increasing order of ti.

Output

If there is no doubt that somebody who was neither a smuggler nor a cargo owner visited the bar, print "Liar" on a single line. Otherwise, print a line "No reason". And in the following lines list information on all visitors of the bar. The information about a visitor consists of two space-separated numbers — the time this visitor entered the bar and the time he left the bar. If there are multiple solutions that correspond to the sensor records, print any of them.

Sample Input

6 3

4

1 0

2 0

5 1

10 1

Sample Output

No reason

1 10

2 5

Hint

题意

这个星球有两种人,一种人进酒吧至少玩a小时,一种人进酒吧最多玩b小时

现在给你这个酒吧进进出出的时间,问你是否存在一组合法解

题解:

显然的二分图匹配,把合法的进入和退出的,连一条边

然后去跑匈牙利就好了

最后输出一组解

代码

#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e3 + 15;
int a , b , n , idx[maxn] , vis[maxn] , Left[maxn] , halft[maxn] , harht[maxn];
vector < int > lft[maxn] , rht[maxn];
pair < int , int > p[maxn]; void Build_Graph(){
int curlft = 0 , currht = 0;
for(int i = 1 ; i <= n ; ++ i)
if( p[i].second == 0 ){
idx[i] = ++ curlft;
halft[curlft] = i;
}
else{
idx[i] = ++ currht;
harht[currht] = i;
}
for(int i = 1 ; i <= n ; ++ i){
for(int j = i + 1 ; j <= n ; ++ j){
if(p[i].second == 0 && p[j].second == 1){
if( p[j].first - p[i].first >= a){
lft[idx[i]].push_back( idx[j] );
rht[idx[j]].push_back( idx[i] );
}
if( p[j].first - p[i].first <= b){
lft[idx[i]].push_back( idx[j] );
rht[idx[j]].push_back( idx[i] );
}
}
}
}
} int dfs(int x){
for(auto it : lft[x]){
if(Left[it] == -1){
Left[it] = x;
return 1;
}
if(vis[it]) continue;
vis[it] = 1;
if(dfs(Left[it])){
Left[it] = x;
return 1;
}
}
return 0;
} int main(int argc,char *argv[]){
int t = 0;
scanf("%d%d%d",&a,&b,&n);
for(int i = 1 ; i <= n ; ++ i){
scanf("%d%d",&p[i].first,&p[i].second);
if( p[i].second == 0 ) t ++ ;
else t--;
}
if( t ) printf("Liar\n");
else{
Build_Graph();
int match = 0;
memset(Left , -1 , sizeof( Left ) );
for(int i = 1 ; i <= n / 2 ; ++ i){
memset( vis , 0 , sizeof( vis ) );
match += dfs( i );
}
if( match != n / 2 ) printf("Liar\n");
else{
printf("No reason\n");
for(int i = 1 ; i <= n / 2 ; ++ i){
int ri = harht[i] , li = halft[Left[i]];
printf("%d %d\n" , p[li].first , p[ri].first );
}
}
}
return 0;
}

URAL 1997 Those are not the droids you're looking for 二分图最大匹配的更多相关文章

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

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

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

  3. 二分图最大匹配(匈牙利算法) URAL 1721 Two Sides of the Same Coin

    题目传送门 /* 题意:三种人,statements,testdata,anthing.要求两个人能完成s和t两个工作,且rank相差2 二分图匹配:此题学习建图技巧,两个集和内部一定没有边相连,ra ...

  4. ACRush 楼天成回忆录

    楼教主回忆录: 利用假期空闲之时,将这几年 GCJ , ACM , TopCoder 参加的一些重要比赛作个回顾.首先是 GCJ2006 的回忆. Google Code Jam 2006 一波三折: ...

  5. [转]带花树,Edmonds's matching algorithm,一般图最大匹配

    看了两篇博客,觉得写得不错,便收藏之.. 首先是第一篇,转自某Final牛 带花树……其实这个算法很容易理解,但是实现起来非常奇葩(至少对我而言). 除了wiki和amber的程序我找到的资料看着都不 ...

  6. 楼天城楼教主的acm心路历程(作为励志用)

    楼主个人博客:小杰博客 利用假期空暇之时,将这几年GCJ,ACM,TopCoder 參加的一些重要比赛作个 回顾.昨天是GCJ2006 的回顾,今天时间上更早一些吧,我如今还清晰记得3 年 前,我刚刚 ...

  7. BZOJ 2718: [Violet 4]毕业旅行( 最长反链 )

    一不小心速度就成了#1.... 这道题显然是求最长反链, 最长反链=最小链覆盖.最小链覆盖就是先做一次floyd传递闭包, 再求最小路径覆盖. 最小路径覆盖=N - 二分图最大匹配. 所以把所有点拆成 ...

  8. ACM学习大纲

    1 推荐题库 •http://ace.delos.com/usaco/ 美国的OI 题库,如果是刚入门的新手,可以尝试先把它刷通,能够学到几乎全部的基础算法极其优化,全部的题解及标程还有题目翻译可以b ...

  9. 【转】楼天城楼教主的acm心路历程(作为励志用)

    利用假期空闲之时,将这几年GCJ,ACM,TopCoder 参加的一些重要比赛作个回顾.昨天是GCJ2006 的回忆,今天时间上更早一些吧,我现在还清晰记得3 年前,我刚刚参加ACM 时参加北京赛区2 ...

随机推荐

  1. React Native 快速入门之认识Props和State

    眼下React Native(以后简称RN)越来越火,我也要投入到学习当中.对于一个前端来说,还是有些难度.因为本人觉得这是一个App开发的领域,自然是不同.编写本文的时候,RN的版本为0.21.0. ...

  2. effective c++读书笔记(一)

    很早之前就听过这本书,找工作之前读一读.看了几页,个人感觉实在是生涩难懂,非常不符合中国人的思维方式.之前也有博主做过笔记,我来补充一些自己的理解. 我看有人记了笔记,还不错:http://www.3 ...

  3. poj 1077(BFS预处理+康托展开)

    Eight Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29935   Accepted: 13029   Special ...

  4. jmeter----计数器

    在测试过程中,往往需要一些有一定规则的数字,这个时候,可以使用配置元件中的计数器去实现. 一.界面显示 二.配置说明 1.名称:标识 2.注释:备注 3.启动:是指计数器开始的值 4.递增:每次增加的 ...

  5. 使用OpenSSL自签发服务器https证书

    OpenSSL官方推荐win32可执行文件版下载:http://www.slproweb.com/products/Win32OpenSSL.html ca.key CA私钥: openssl gen ...

  6. 在ubuntu下安装kaldi基本步骤

    注:最近在学习kaldi语音识别工具,在安装过程中遇到了许多问题,在此记录,以备后需. 在一开始,我看了这篇博客(http://blog.topspeedsnail.com/archives/1001 ...

  7. Centos7 ocsp功能验证

    转载:https://blog.csdn.net/tsh185/article/details/8107248 先按照Centos7创建CA和申请证书创建PKI所需要的文件 运行服务器端: opens ...

  8. CodeForces 797D Broken BST

    $dfs$,线段树. 通过观察可以发现,某位置要能被找到,和他到根这条路上的每个节点的权值存在密切的联系,且是父节点的左儿子还是右儿子也有联系. 可以从根开始$dfs$,边走边更新线段树,如果遍历左儿 ...

  9. 洛谷P3459 [POI2007]MEG-Megalopolis [树链剖分]

    题目传送门 MEG 题目描述 Byteotia has been eventually touched by globalisation, and so has Byteasar the Postma ...

  10. python 写一个贪吃蛇游戏

    #!usr/bin/python #-*- coding:utf-8 -*- import random import curses s = curses.initscr() curses.curs_ ...