概述
A. Spit Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 d meters 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 di correspond 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.
Sample test(s)
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 |
题意:话说,这个骆驼一点都不文明,还吐痰,吐痰就算了,还要我算会不会相互吐到对方身上。有的往左吐,有的往右吐,反正都是在坐标轴上就对了。
思路:暴力解决
code:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
using namespace std;
struct node
{
int x,d;
}a[105];
int main()
{
int n;
int flag=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d%d",&a[i].x,&a[i].d);
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
if((a[i].x+a[i].d==a[j].x)&&(a[i].x==a[j].x+a[j].d)){
flag=1;
break;
}
}
if(flag)
break;
}
if(flag)
printf("YESn");
else
printf("NOn");
return 0;
}
最后
以上就是无辜钢笔为你收集整理的【codeforces 29A】Spit Problem的全部内容,希望文章能够帮你解决【codeforces 29A】Spit Problem所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复