我是靠谱客的博主 魔幻羽毛,最近开发中收集的这篇文章主要介绍CodeForces - 29A - Spit Problem,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

题目出处:codeforces - 29A

A. Spit Problem
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



水题,计算下每个终点,比较起点和终点不在同一点,就吐不到

the accepted code like this :


//
//  main.cpp
//  CF29A
//
//  Created by IntelliegeWither on 15/12/2.
//  Copyright © 2015年 IntelliegeWither. All rights reserved.
//

#include<stdio.h>
int main()
{
    int a[105],d[105],zd[105];
    int n;
    int i,j,sign=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&a[i],&d[i]);
        zd[i]=a[i]+d[i];
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i!=j&&a[i]==zd[j]&&a[j]==zd[i])//相互吐不中,标记
            {
                sign=1;
            }
        }
    }
    if(sign)
    {
        printf("YESn");
    }
    else
    {
        printf("NOn");
    }
}


最后

以上就是魔幻羽毛为你收集整理的CodeForces - 29A - Spit Problem的全部内容,希望文章能够帮你解决CodeForces - 29A - Spit Problem所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(40)

评论列表共有 0 条评论

立即
投稿
返回
顶部