码迷,mamicode.com
首页 > 其他好文 > 详细

BestCoder Round #61 1001 Numbers

时间:2015-10-31 22:59:17      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:

Problem Description

There are n numbers A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A?1??,A?2??....A?n??,your task is to check whether there exists there different positive integers i, j, k (1≤i,j,k≤n1\leq i , j , k \leq n1i,j,kn) such that Ai−Aj=Ak{A}_{i}-{A}_{j}={A}_{k}A?i??A?j??=A?k??

Input

There are multiple test cases, no more than 1000 cases. First line of each case contains a single integer n.(3≤n≤100)(3\leq n\leq 100)(3n100). Next line contains n integers A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A?1??,A?2??....A?n??.(0≤Ai≤1000)(0\leq {A}_{i}\leq 1000)(0A?i??1000)

Output

For each case output "YES" in a single line if you find such i, j, k, otherwise output "NO".

Sample Input
3
3 1 2
3
1 0 2
4
1 1 0 2
Sample Output
YES
NO
YES

大水题,快排一下两个循环搞一下就好 23333 用goto嘲讽了,我的锅
技术分享
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int donser(const void *a,const void *b)
{
    return *(int *)a-*(int *)b;
}
int main()
{
    freopen("in.txt","r",stdin);
    int i,j,k,m,d[2000];
    while(~scanf("%d",&m))
    {
        for(i=1;i<=m;i++)
        {
            scanf("%d",&d[i]);
        }
        qsort(d+1,m,sizeof(int),donser);
        if(m<3){cout<<"NO\n";goto n;}
        for(i=1;i<=m-2;i++)
        {
            for(k=i+1;k<=m-1;k++)
            {
                for(j=k+1;j<=m;j++)
                {
                    if(d[i]+d[k]==d[j]){cout<<"YES\n";goto n;}
                }
            }    
        }
        cout<<"NO\n";
        n: m=0;
        for(i=1;i<=m;i++)
        {
            d[i]=0;
        }
    }
    return 0;
}
View Code

 

问题描述
给n个数A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A?1??,A?2??....A?n??,从中选3个位置不同的数A,B和C,问是否有一种情况满足A-B=C.
输入描述
输入有多组数据,不超过1000组.
每组数据第一行包含一个整数n,随后一行n个整数A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A?1??,A?2??....A?n??.(3≤n≤1003\leq n\leq 1003n100,0≤Ai≤10000\leq {A}_{i}\leq 10000A?i??1000)
输出描述
对于每组数据如果符合条件输出"YES",否则输出"NO".
输入样例
3
3 1 2
3
1 0 2
4
1 1 0 2
输出样例
YES
NO
YES

BestCoder Round #61 1001 Numbers

标签:

原文地址:http://www.cnblogs.com/dzzy/p/4926346.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!