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

不超过30行 0ms AC ^_^

Posted by yuanyirui at 2007-04-28 18:15:19 on Problem 1338
In Reply To:请问怎样不超时 Posted by:SinsongLew at 2007-04-15 14:26:25
//我的是 o(n) 的,计算1500次就可以了..
#include <stdio.h>
int main()
{
    int a[1505],an,i,two,three,five,n;
    a[0]=1;
    two=three=five=0;
    for(an=1;an<1500;an++){
        if(a[two]*2<=a[three]*3 && a[two]*2<=a[five]*5){
            if(a[two]*2==a[three]*3 && a[two]*2==a[five]*5) three++ , five++;
            else if(a[two]*2==a[three]*3) three++;
            else if(a[two]*2==a[five]*5) five++;
            a[an]=a[two++]*2;
        }
        else if(a[three]*3<=a[two]*2 && a[three]*3<=a[five]*5){
            if(a[three]*3==a[two]*2) two++;
            else if(a[three]*3==a[five]*5) five++;
            a[an]=a[three++]*3;
        }
        else if(a[five]*5<=a[two]*2 && a[five]*5<=a[three]*3){
            if(a[five]*5==a[two]*2) two++;
            else if(a[five]*5==a[three]*3) three++;
            a[an]=a[five++]*5;
        }
    }
    while(scanf("%d",&n) && n!=0) printf("%d\n",a[n-1]);
}

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