BestCoder Round #61 1001 Numbers

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 n1≤i,j,k≤n) 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)(3≤n≤100). 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)(0≤A​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[];
while(~scanf("%d",&m))
{
for(i=;i<=m;i++)
{
scanf("%d",&d[i]);
}
qsort(d+,m,sizeof(int),donser);
if(m<){cout<<"NO\n";goto n;}
for(i=;i<=m-;i++)
{
for(k=i+;k<=m-;k++)
{
for(j=k+;j<=m;j++)
{
if(d[i]+d[k]==d[j]){cout<<"YES\n";goto n;}
}
}
}
cout<<"NO\n";
n: m=;
for(i=;i<=m;i++)
{
d[i]=;
}
}
return ;
}
问题描述
给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 1003≤n≤100,0≤Ai≤10000\leq {A}_{i}\leq 10000≤A​i​​≤1000)
输出描述
对于每组数据如果符合条件输出"YES",否则输出"NO".
输入样例
3
3 1 2
3
1 0 2
4
1 1 0 2
输出样例
YES
NO
YES
上一篇:easyui 1.3.3 中combotree post传参问题


下一篇:非抢占式RCU实现(一)