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

对前面大牛算法的改进

Posted by lisency at 2012-03-20 17:57:51 on Problem 1338
In Reply To:以轻易的脚步走掉我的第50题,菜鸟也,任重道远(附代码) Posted by:547880119 at 2009-02-24 18:05:15
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int mul2 = 2,mul3 = 3,mul5 = 5,t = 0;
    int i = 1,j = 1,k = 1;

    long result[1500 + 1] = {0};
    result[1] = 1;
    int index = 2;

    for (;index <= 1500;++index)
    {
        t = min(mul2,min(mul3,mul5));
        result[index] = t;
        if (t == mul2)
            mul2 = result[++i] * 2;
        if (t == mul3)
            mul3 = result[++j] * 3;
        if (t == mul5)
            mul5 = result[++k] * 5;
    }
    while (cin >> index,index > 0)
    {
        cout << result[index] << endl;
    }
    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