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. CIFAR-10数据集图像分类【PCA+基于最小错误率的贝叶斯决策】

    CIFAR-10和CIFAR-100均是带有标签的数据集,都出自于规模更大的一个数据集,他有八千万张小图片.而本次实验采用CIFAR-10数据集,该数据集共有60000张彩色图像,这些图像是32*32 ...

  2. Java性能优化之String字符串优化

    字符串是软件开发中最重要的对象之一.通常,字符串对象在内存中是占据了最大的空间块,因此如何高效地处理字符串,必将是提高整体性能的关键所在. 1.字符串对象及其特点 Java中八大基本数据类型没有Str ...

  3. JS prototype 生成机制

    默认的 prototype 属性是 Object() 对象,只不过每种类型或者自定义类型锁挂载的对象属性不同. 事实上,prototype 的生成是这样的: const Func = function ...

  4. Omi教程-组件通讯攻略大全

    组件通讯 Omi框架组建间的通讯非常遍历灵活,因为有许多可选方案进行通讯: 通过在组件上声明 data-* 传递给子节点 通过在组件上声明 data 传递给子节点 (支持复杂数据类型的映射) 父容器设 ...

  5. Linux 的系统目录介绍

    /bin 二进制可执行命令 /dev 设备特殊文件/etc 系统管理和配置文件/etc/rc.d 启动的配置文件和脚本/home 用户主目录的基点,比如用户user的主目录就是/home/user,可 ...

  6. 二十二:制作app的时候超出部分不能滑动

    给需要滑动的区域写以下样式(父级是浏览器) position: absolute; left: 0; right: 0; bottom: 0; top: 0; overflow-x: hidden; ...

  7. 海康威视笔试(C++)

    1. select和epoll的区别 2.服务器并发量之高性能服务器设计 3.SQL关键字 4.TCP乱序和重传的问题 5.c++对象内存分配问题 6.c++多线程 join的用法: Thread类的 ...

  8. Win10系统如何安装Linux Mint

    导读 随着windows10系统免费升级期限的靠近,越来越多朋友都将自己的电脑系统升级到了win10正式版.今天,小编就要在这里为大家分享Windows10系统安装Linux Mint的方法,希望能够 ...

  9. case when then的用法-leetcode交换工资

    case具有两种格式:简单case函数和case搜索函数. --简单case函数 case sex when ' then '男' when ' then '女’ else '其他' end --ca ...

  10. 抽象代数-p22商群

    G/e={g{e}|g∈G}={{g}|g∈G}=G G/G={gG|g∈G}={G}   (gG=G左乘g是G上的双射,它的逆映射是左乘g^-1)  所以 G/G  只有一个元素,所有G  就只能是 ...