zoukankan      html  css  js  c++  java
  • codeforces29A

    Spit Problem

     CodeForces - 29A 

    In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.

    The trajectory of a camel's spit is an arc, i.e. if the camel in position x spits dmeters right, he can hit only the camel in position x + d, if such a camel exists.

    Input

    The first line contains integer n (1 ≤ n ≤ 100) — the amount of camels in the zoo. Each of the following n lines contains two integers xi and di ( - 104 ≤ xi ≤ 104, 1 ≤ |di| ≤ 2·104) — records in Bob's notepad. xi is a position of the i-th camel, and di is a distance at which the i-th camel spitted. Positive values of dicorrespond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position.

    Output

    If there are two camels, which spitted at each other, output YES. Otherwise, output NO.

    Examples

    Input
    2
    0 1
    1 -1
    Output
    YES
    Input
    3
    0 1
    1 1
    2 -2
    Output
    NO
    Input
    5
    2 -10
    3 10
    0 5
    5 -5
    10 1
    Output
    YES

    sol:并不知道P该怎么做,反正我是C,我有map。。。
    #include <bits/stdc++.h>
    using namespace std;
    typedef int ll;
    inline ll read()
    {
        ll s=0;
        bool f=0;
        char ch=' ';
        while(!isdigit(ch))
        {
            f|=(ch=='-'); ch=getchar();
        }
        while(isdigit(ch))
        {
            s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
        }
        return (f)?(-s):(s);
    }
    #define R(x) x=read()
    inline void write(ll x)
    {
        if(x<0)
        {
            putchar('-'); x=-x;
        }
        if(x<10)
        {
            putchar(x+'0');    return;
        }
        write(x/10);
        putchar((x%10)+'0');
        return;
    }
    #define W(x) write(x),putchar(' ')
    #define Wl(x) write(x),putchar('
    ')
    const int N=105;
    int n,X[N],D[N];
    map<int,bool>Bo;
    map<int,int>Id;
    int main()
    {
        int i;
        R(n);
        for(i=1;i<=n;i++)
        {
            R(X[i]); R(D[i]); Bo[X[i]]=1; Id[X[i]]=i;
        }
        for(i=1;i<=n;i++) if(Bo[X[i]+D[i]])
        {
            int oo=Id[X[i]+D[i]];
            if(Id[X[oo]+D[oo]]==i) return puts("YES"),0;
        }
        puts("NO");
        return 0;
    }
    /*
    Input
    2
    0 1
    1 -1
    Output
    YES
    
    Input
    3
    0 1
    1 1
    2 -2
    Output
    NO
    
    Input
    5
    2 -10
    3 10
    0 5
    5 -5
    10 1
    Output
    YES
    */
    View Code
     
  • 相关阅读:
    【TS】535- 7个超好用的 TypeScript 新功能
    【学习】一起加入重学 TypeScript 学习小组
    17.5W秒级交易峰值下的混合云弹性架构之路
    微服务架构:spring cloud之服务注册和服务发现
    消息队列服务RabbitMQ 和Kafka对比
    微服务架构:spring cloud简介
    2016 年度码云热门项目排行榜 TOP 10
    Netflix Conductor : 一个微服务的编排器
    Java 9的这一基本功能,你可能从未听过
    使用 Docker 搭建 Java Web 运行环境
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10738408.html
Copyright © 2011-2022 走看看