Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这个0MS可以AC,不过也是暴力出来的。

Posted by prowind at 2008-12-29 22:47:19 on Problem 1543
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator