Posted on 2008-03-14 16:16
superman 阅读(394)
评论(0) 编辑 收藏 引用 所属分类:
ZOJ
1 /* Accepted 1101 C++ 00:00.22 848K */
2 #include <stdlib.h>
3 #include <iostream>
4
5 using namespace std;
6
7 int cmp(const void * a, const void * b)
8 {
9 return *(int*)a - *(int*)b;
10 }
11
12 int n;
13 int x[1000];
14
15 void solve()
16 {
17 for(int k = n - 1; k >= 0; k--)
18 for(int i = 0; i < n; i++)
19 for(int j = i + 1; j < n; j++)
20 if(i != k && j != k)
21 {
22 int left = x[k] - (x[i] + x[j]);
23
24 if(left == x[i] || left == x[j] || left == x[k])
25 continue;
26
27 if(bsearch(&left, x, n, sizeof(int), cmp))
28 {
29 cout << x[k] << endl;
30 return;
31 }
32 }
33 cout << "no solution" << endl;
34 }
35
36 int main()
37 {
38 while((cin >> n) && n)
39 {
40 for(int i = 0; i < n; i++)
41 cin >> x[i];
42
43 qsort(x, n, sizeof(int), cmp);
44
45 solve();
46 }
47
48 return 0;
49 }
50