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=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,X[N],D[N];
map<int,bool>Bo;
map<int,int>Id;
int main()
{
int i;
R(n);
for(i=;i<=n;i++)
{
R(X[i]); R(D[i]); Bo[X[i]]=; Id[X[i]]=i;
}
for(i=;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"),;
}
puts("NO");
return ;
}
/*
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
*/
 

codeforces29A的更多相关文章

随机推荐

  1. Groovy语言学习--语法基础(4)

    语法基础到此就结束了,毕竟其和Java许多地方并无差别.groovy作为脚本,是为了能更好地随业务变化调整规则,我根据自己对规则的理解 通过一张图简单描述一个groovy脚本场景:由于货币膨胀,经济收 ...

  2. 封装自己的dapper lambda扩展-设计篇

    前言 昨天开源了业务业余时间自己封装的dapper lambda扩展,同时写了篇博文<编写自己的dapper lambda扩展-使用篇>简单的介绍了下其使用,今天将分享下它的设计思路 链式 ...

  3. LeetCode 595. Big Countries

    There is a table World +-----------------+------------+------------+--------------+---------------+ ...

  4. JSF生存指南P1

    这是OO的第三次博客作业,也是JSFO(面向JSF编程)的第一次博客作业.暗示了我们面向对象课程已经再向JSF的编写过渡. 不知不觉OO的作业已经写完3/4,那些熬夜赶作业的日子仍然历历在目,仿佛是昨 ...

  5. Python-模块导入-63

    模块导入: # 内置模块 # 扩展的 django # 自定义的 # 文件 # import demo # def read(): # print('my read func') # demo.rea ...

  6. Git Gerrit Code Review

    Gerrit Code Review | Gerrit Code Reviewhttps://www.gerritcodereview.com/

  7. JEECG框架中使用Flash版本Uploadify,在Chrome版本号70下无法启动的解决办法

    感谢文章:https://www.cnblogs.com/zinan/p/6902427.html 单独打开IFRAME中的页面 点击导航栏的<不安全> 再刷新单独IFRAME的页面,就可 ...

  8. node错误中间件处理 express类 带有路由操作

    let express = require('express'); let app = new express(); let bodyParser = require('body-parser'); ...

  9. C#复习笔记(1)--C#开发的进化史

    前言:陆续使用C#已经有一年半的时间.中间做过一些应用,现在为了有更高的提升,决定重新看一遍C# in depth,并总结一些笔记. 一.从简单的数据类型开始 上面是C#1到C#4中的一部分演变历程. ...

  10. vue2.0生命周期

    https://www.cnblogs.com/goloving/p/8616989.html(copy )