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

1338大牛那学来的。贴代码。

Posted by hch545767949 at 2013-02-13 23:28:07 on Problem 2591
#include<stdio.h>
int min(int a,int b)
{
    if(a<=b)
        return a;
    else return b;
}
int data[10000001];
int main()
{
    int n,two=1,three=1;
    data[1]=1;

    for(int i=2;i<=10000000;i++)
    {
        data[i]=min(data[two]*2+1,data[three]*3+1);
        if(data[i]==data[two]*2+1)
            two++;
        if(data[i]==data[three]*3+1)
            three++;
    }
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",data[n]);
    }
    return 0;
}

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