Posted on 2008-06-20 17:08
superman 阅读(469)
评论(0) 编辑 收藏 引用 所属分类:
ZOJ
1 /* Accepted 1331 C++ 00:00.23 836K */
2 #include <iostream>
3
4 using namespace std;
5
6 int cmp(const void * a, const void * b)
7 {
8 return *(int*)a - *(int*)b;
9 }
10
11 int main()
12 {
13 cout << "Cube = 6, Triple = (3,4,5)" << endl;
14 cout << "Cube = 12, Triple = (6,8,10)" << endl;
15 cout << "Cube = 18, Triple = (2,12,16)" << endl;
16 cout << "Cube = 18, Triple = (9,12,15)" << endl;
17 cout << "Cube = 19, Triple = (3,10,18)" << endl;
18 cout << "Cube = 20, Triple = (7,14,17)" << endl;
19
20 int x[202];
21 for(int i = 2; i <= 200; i++)
22 x[i] = i * i * i;
23
24 for(int n = 24; n <= 200; n++)
25 for(int a = 2; a < n; a++)
26 for(int b = 2; b < n; b++)
27 if(a < b)
28 {
29 int c = x[n] - x[a] - x[b];
30 if(c <= 0)
31 continue;
32 int *p = (int*)bsearch(&c, x, n, sizeof(int), cmp);
33 if(p && p - x > b)
34 printf("Cube = %d, Triple = (%d,%d,%d)\n", n, a, b, p - x);
35 }
36
37 return 0;
38 }
39