荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: Version (Who makes history and why), 信区: Program
标  题:  一道算法题解法(3) (转载)
发信站: 荔园晨风BBS站 (Mon Mar 24 18:05:22 2003), 站内信件

#include <iostream>
#include <list>

using namespace std;
typedef list<int>  INTLIST;
int fun(int n)
{
    INTLIST  nList;
    nList.push_back(1);
    nList.push_back(2)
    nList.push_back(3);
    int nIndex = 3;
    int nMax = 3;
    int nPar[] = {2,3,5};
    while(nIndex <= n)
    {
        INTLIST::iterator ite = nList.begin();
        int nMin = 0;
        while(ite != nList.end())
        {
            int nTmp = *(ite);
            int i;
            for(i = 0; i < 3; i ++)
            {
                if(nTmp * nPar[i] > nMax)
                {
                     if(nMin)
                         nMin = _MIN(nMin, nTmp * nPar[i]);
                     else
                         nMin = nTmp * nPar[i];
                     break;
                 }
            }
            if(nMin && i == 0)
            {
                 nMax = nMin;
                 nList.push_back(nMin);
                 nIndex ++;
              cout << "nIndex = " <<nIndex << "\t nMax = " << nMax <<endl;
                 break;
             }else if(nMin == 0 && i == 3)
            {
                 nList.pop_front();
                 break;
             }
             ite++;
       }
    }
    return nMax;
}


void main()
{
        cout << "the bunber is " <<fun(1500) <<endl;
}


--
                      *
          *                                  *
                          *             *
                      no more to say
                  ★     just wish you   ★
                            good luck

※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.1.50]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店