Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/262144 K (Java/Others)
Total Submission(s): 32 Accepted Submission(s): 28
Problem Description
There are n numbers
A1,A2....An
,your task is to check whether there exists there different positive integers i, j, k (
1≤i,j,k≤n
) such that
Ai−Aj=Ak
Input
There are multiple test cases, no more than 1000 cases.
First line of each case contains a single integer n. (3≤n≤100) .
Next line contains n integers A1,A2....An . (0≤Ai≤1000)
First line of each case contains a single integer n. (3≤n≤100) .
Next line contains n integers A1,A2....An . (0≤Ai≤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
题意:给出一串数字,问是否存在不同位置上的数字a,b,c满足于a-b=c。
Bestcoder数据真心弱啊,枚举就过了。
代码如下:
#include<cstdio>
int main()
{
int n,a[1010],i,j,k;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;++i)
scanf("%d",&a[i]);
int sign=0;
for(i=0;i<n;++i)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;++k)
{
if(i!=j&&i!=k&&j!=k)
{
if(a[k]==(a[i]-a[j]))
{
sign=1;
break;
}
}
}
}
}
if(sign)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}