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. ExFilePicker的使用 — 获取本地图片资源并用RecyclerView展示出来

    代码其实很简单,所以就不多进行文字说明,直接上完整的代码: 第一步:在app/build.gradle添加需要使用到的依赖库:(这里对引用的版本冲突问题作了处理,详情请看链接:https://www. ...

  2. 不可变对象和Biulder模式(面试问题)

    String就是一个典型的不可变对象.外界的操作不能改变它,如果尝试改变都会返回一个新的String对象. 具体实现起来就是把属性全部变成private 和 final的,这个类也是final的不可继 ...

  3. linux用法总结

    scp -r -P 22 /srv/ox/demo ps@192.168.1.15:/home/ps/    本地demo目录文件传到ps下 cp -r  /home/ps/demo  srv/ox/ ...

  4. Storm-HA 配置

    进入storm/conf目录,修改storm.yaml配置文件为如下内容: # zookeeper ip storm.zookeeper.servers: - "192.168.7.108& ...

  5. 修改docker0默认IP地址

    第一步:vim /etc/docker/daemon.json { "registry-mirrors": ["https://docker.mirrors.ustc.e ...

  6. Redux 入门教程(三):React-Redux 的用法

    为了方便使用,Redux 的作者封装了一个 React 专用的库 React-Redux,本文主要介绍它. 这个库是可以选用的.实际项目中,你应该权衡一下,是直接使用 Redux,还是使用 React ...

  7. 03-HTML之body标签

    body标签 HTML标签按作用主要分为两类:字体标签和排版标签 HTML标签按级别主要分为两类:文本级标签和容器级标签 文本级标签:p.span.a.b.i.u.em.文本标签里只能放文字.图片.表 ...

  8. jQuery基础语法知识梳理

    一.attr() attr()方法设置或返回元素的属性. attr(属性名):获取元素属性名的值. attr(属性名,属性值):设置元素属性名的值. 例子: <a href=”http://12 ...

  9. TCP 原理

    一.分组交换网络   古老的电话通信,一根电缆,两个用户设备通信 计算机中的两个设备节点通信:分组网络 计算机网络采取分组交换技术,意思就是我有[一块数据]要发给对方,那我会把这[一块数据]分成N份[ ...

  10. [2017BUAA软工助教]团队alpha得分总表

    一.累计得分 项目 介绍 采访 贡献分 功能 技术 α例会 α发布 α测试 α展示 α事后 合计 满分 10 10 10 10 10 50 10 10 150 10 280 hotcode5 10 9 ...