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
     
  • 相关阅读:
    TensorFlow基础篇
    MySql分类
    VISUAL STUDIO 调试
    排序分类
    位分类
    Visio分类
    工作线程AfxBeginThread的使用
    Windows Live Writer配置步骤
    用户界面线程AfxBeginThread的使用
    WIndows 相关知识
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10738408.html
Copyright © 2011-2022 走看看