Time Limit: 20 Sec
Memory Limit: 256 MB
http://acm.hdu.edu.cn/showproblem.php?pid=5522
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)
Output
For each case output "YES" in a single line if you find such i, j, k, otherwise output "NO"
Sample Input
Sample Output
YES
NO
YES
题意
题解:
就n^2暴力,先排序然后从大到小枚举i,把右边的数用一个数组标记其出现过,再枚举左边的数判断其加上Ai是否出现过.
代码
#include<iostream> #include<stdio.h> #include<algorithm> #include<map> using namespace std; map<int,int> H; int a[101]; int main() { int n; while(scanf("%d",&n)!=EOF) { H.clear(); for(int i=1;i<=n;i++) scanf("%d",&a[i]),H[a[i]]++; sort(a+1,a+1+n); int flag = 0; for(int i=1;i<=n;i++) { H[a[i]]--; for(int j=1;j<i;j++) if(H[a[j]+a[i]]) flag = 1; if(flag) break; } if(flag) printf("YES\n"); else printf("NO\n"); } }
原文:http://www.cnblogs.com/qscqesze/p/4928186.html