ZOJ1331
#include <iostream>
#include <cstdlib>
using namespace std;
const int MAX_SIZE = 202;
int Cube[MAX_SIZE];
int cmp(const void *p,const void *q)
{
return *(int *)p - *(int *)q;
}
int main()
{
int i,a,b,c,n;
int *p;
for(i = 1; i <= 200; i++)
Cube[i] = i*i*i;//记录下1~200相对应的立方
for(n = 6; n <= 200; n++)
for(a = 2; a < n; a++)
for(b = a ; b <= n; b++)
{
c = Cube[n] - Cube[a] - Cube[b];
if(c <= 0)continue;
if(c < Cube[b])continue;//满足a <= b <= c
p = (int *)bsearch(&c,Cube,n,sizeof(int),cmp);
if(p)
cout<<"Cube = "<<n<<", Triple = ("<<a<<","<<b<<","<<p - Cube<<")"<<endl;
}
return 0;
}
#include <cstdlib>
using namespace std;
const int MAX_SIZE = 202;
int Cube[MAX_SIZE];
int cmp(const void *p,const void *q)
{
return *(int *)p - *(int *)q;
}
int main()
{
int i,a,b,c,n;
int *p;
for(i = 1; i <= 200; i++)
Cube[i] = i*i*i;//记录下1~200相对应的立方
for(n = 6; n <= 200; n++)
for(a = 2; a < n; a++)
for(b = a ; b <= n; b++)
{
c = Cube[n] - Cube[a] - Cube[b];
if(c <= 0)continue;
if(c < Cube[b])continue;//满足a <= b <= c
p = (int *)bsearch(&c,Cube,n,sizeof(int),cmp);
if(p)
cout<<"Cube = "<<n<<", Triple = ("<<a<<","<<b<<","<<p - Cube<<")"<<endl;
}
return 0;
}