//poj1011无限wa,做道简单的,直接暴力竟然AC啦 //大意:输出所有满足a^3 = b^3 + c^3 + d^3 的a #include#include using namespace std;int m(int m){ return m*m*m;}int main(){ int i,j,k,n,p; cin>>n; for(p=6;p<=n;p++) for(i=2;i<=n-1;i++)//已经保证bcd互不相等 for(j=i+1;j<=n-1;j++) for(k=j+1;k<=n-1;k++) if(m(i)+m(j)+m(k)==m(p)) cout<<"Cube = "< <<","<<" Triple = ("<<<","<
<<","< <<")"< #include #include #include using namespace std;bool vis[101];int cute[101];int res[5];int T,step=1;void init(){ int i,j;//原来写成了,i = 10,怪不得一直wa for(i=1;i<=101;i++) cute[i] = i*i*i;}void dfs(int num,int start,int n){ int i,j,k; if(step==4) { if(num==0) printf("Cube = %d, Triple = (%d,%d,%d)\n",n, res[1], res[2], res[3] ); } else { for(i=start;cute[i]<=num;i++)//必须有等号,否则无法结束(成立时的最后一个数) if(!vis[i]) { vis[i] = true; res[step] = i; step++; dfs(num-cute[i],i+1,n); step--; vis[i] = false; } }} int main(){ int i,j,k; init(); cin>>T; memset(vis,false,sizeof(vis)); for(i=6;i<=T;i++) { step = 1; dfs(cute[i],2,i); } system("pause"); return 0;}