Problem Description
There are n numbers 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≤n
)
such that 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)
.
Next line contains n integers A
1
,A
2
....A
n![]()
.(0≤A
i
≤1000)![]()
First line of each case contains a single integer n.(3≤n≤100)
Next line contains n integers A
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
题意·:输入几个数,问是否存在任意两个数之差依然在这几个数之中(除这两个数之外)
分析:暴力枚举
AC代码如下:
#include "stdio.h"
#include "math.h"
int main(int argc, char* argv[])
{
int n,a[120];
int i,j,k,flag;
while (scanf("%d",&n)!=EOF)
{
flag=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{
if (abs(a[i]-a[j])==a[k]&&i!=j&&j!=k&&i!=k)
{
flag=1;
}
}
}
}
if (flag)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return 0;
}