URAL1997-Those are not the droids you're looking for
来源:互联网 发布:淘宝 手环 编辑:程序博客网 时间:2024/05/27 21:48
1997. Those are not the droids you're looking for
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
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.
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 ≤ 109, 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 ≤ 109, 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.
Samples
6 341 02 05 110 1
No reason1 102 5
6 341 02 06 110 1
Liar
Problem Author: Denis Dublennykh (prepared by Oleg Dolgorukov)
题意:有两种人,一种进酒吧至少玩a小时,另一种进酒吧最多玩b小时。下面n行是人进进出出的时刻,0为进,1为出。求是否有合法解
解题思路:将合法的进入和出去连边,然后二分匹配就可以了#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <set>#include <map>#include <algorithm>#include <vector>#include <stack>#include <queue>using namespace std;const int INF=0x3f3f3f3f;#define LL long longint n,mat,mit;int x[1109],y[1109];int xs[1005],ys[1005];int xn,yn;int s[1109],nt[1000009],e[1000009];int visit[1109];bool path(int k){ for(int i=s[k];~i;i=nt[i]) { int ee=e[i]; if(!visit[ee]) { visit[ee]=1; if(y[ee]==-1||path(y[ee])) { y[ee]=k; x[k]=ee; return 1; } } } return 0;}void MaxMatch(){ int ans=0; memset(x,-1,sizeof x); memset(y,-1,sizeof y); for(int i=0;i<xn;i++) { if(x[i]==-1) { memset(visit,0,sizeof visit); if(path(i)) ans++; } } if(ans==xn) { printf("No reason\n"); for(int i=0;i<xn;i++) printf("%d %d\n",xs[i],ys[x[i]]); } else printf("Liar\n");}int main(){ while(~scanf("%d %d",&mat,&mit)) { int cnt=0; xn=yn=0; int t,p; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d%d",&t,&p); if(p==0) xs[xn++]=t; else ys[yn++]=t; } if(yn!=xn) { printf("Liar\n"); continue; } memset(s,-1,sizeof s); for(int i=0;i<xn;i++) { for(int j=0;j<yn;j++) { if((ys[j]-xs[i]>=0&&ys[j]-xs[i]<=mit)||ys[j]-xs[i]>=mat) nt[cnt]=s[i],s[i]=cnt,e[cnt++]=j; } } MaxMatch(); } return 0;}
0 0
- URAL1997-Those are not the droids you're looking for
- Those are not the droids you're looking for Gym
- Ural 1997-Those are not the droids you're looking for 二分图匹配
- GYM 100285 H. Those are not the droids you're looking for(二分匹配-Dinic)
- URAL 1997 Those are not the droids you're looking for(二分图)
- 2013-2014 ACM-ICPC, NEERC, Eastern Subregional Contest H:Those are not the droids you're looking for
- What are you looking for on top of the world? English readings.
- The page you are looking for is temporarily unavailable.Please try again later.
- nginx +tomcat The page you are looking for is temporarily unavailable.Please try again later.
- 解决nginx的The page you are looking for is temporarily unavailable错误办法
- the page you are looking for is temporarily unavailable. Please try again later 解决方案
- Nginx+Tomcat7:The page you are looking for is temporarily unavailable.Please try again later.
- Nginx--Sorry, the page you are looking for is currently unavailable
- 解决nginx的The page you are looking for is temporarily unavailable错误办法
- 服务器nginx配置问题the page you are looking for is currently unavailable
- 解决nginx的An error occurred. The page you are looking for is temporarily unavailable错误办法
- What Employers Are Looking For During The Interview Process
- fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module
- AWK学习笔记-2.1Pattern属性
- 题目1107:搬水果 九度OJ
- 运维学习10
- 努力前行
- java数列求和
- URAL1997-Those are not the droids you're looking for
- Linux安装Lantern
- App性能优化之内存优化
- 部署Doxygen生成API文档
- PHP获得真实客户端的真实IP
- JAVA中的冒泡排序和选择排序
- string初始化 n种方法
- oj122. Best Time to Buy and Sell Stock II
- Android实现侧滑(SlidingMenu)