Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这个0MS可以AC,不过也是暴力出来的。In Reply To:Re:水题是勿用质疑的,但是我还是用了360ms,有跟简单的方法吗? Posted by:yogafrank at 2008-11-08 10:51:14 这个0MS可以AC,不过也是暴力出来的。 #include <iostream> using namespace std; int pow(int i){ return i*i*i; } int main(){ int n,a,b,c,d,sum; int p[200]; scanf("%d",&n); for (int i=1;i<=100;i++) p[i] = pow(i); for (a=2;a<=n;a++){ sum =0; for (b=2;b<a;b++){ sum+= p[b]; for (c=b+1;c<a;c++) { sum+=p[c]; if (sum>p[a]) {sum-=p[c];break;} for (d = c+1;d<a;d++){ sum+=p[d]; if (sum==p[a]) printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d); else if (sum>p[a]) {sum-=p[d];break;} sum-=p[d]; } sum-=p[c]; } sum-=p[b]; } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator