URAL1997-Those are not the droids you're looking for

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

Time limit: 1.0 second
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.
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 ≤  ab ≤ 10 9b + 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  t i and  d i (1 ≤  t i ≤ 10 9d i ∈ {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  t i.

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

input output
6 3
4
1 0
2 0
5 1
10 1
No reason
1 10
2 5
6 3
4
1 0
2 0
6 1
10 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 long

int 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
用代码解决这个问题The program committee of the school programming contests, which are often held at the Ural State University, is a big, joyful, and united team. In fact, they are so united that the time spent together at the university is not enough for them, so they often visit each other at their homes. In addition, they are quite athletic and like walking. Once the guardian of the traditions of the sports programming at the Ural State University decided that the members of the program committee spent too much time walking from home to home. They could have spent that time inventing and preparing new problems instead. To prove that, he wanted to calculate the average distance that the members of the program committee walked when they visited each other. The guardian took a map of Yekaterinburg, marked the houses of all the members of the program committee there, and wrote down their coordinates. However, there were so many coordinates that he wasn't able to solve that problem and asked for your help. The city of Yekaterinburg is a rectangle with the sides parallel to the coordinate axes. All the streets stretch from east to west or from north to south through the whole city, from one end to the other. The house of each member of the program committee is located strictly at the intersection of two orthogonal streets. It is known that all the members of the program committee walk only along the streets, because it is more pleasant to walk on sidewalks than on small courtyard paths. Of course, when walking from one house to another, they always choose the shortest way. All the members of the program committee visit each other equally often. Input The first line contains the number n of members of the program committee (2 ≤ n ≤ 105). The i-th of the following n lines contains space-separated coordinates xi, yi of the house of the i-th member of the program committee (1 ≤ xi, yi ≤ 106). All coordinates are integers. Output Output the average distance, rounded down to an integer, that a member of the program committee walks from his house to the house of his colleague.
最新发布
05-26

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值