荔园在线
荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀
[回到开始]
[上一篇][下一篇]
发信人: Version (Who makes history and why), 信区: Program
标 题: 一道算法题解法(2) (转载)
发信站: 荔园晨风BBS站 (Mon Mar 24 18:03:33 2003), 站内信件
我的解法
复杂度是O(n)
using System;
namespace TTF
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
int[] A=new int[1500];
int[] B=new int[1500];
int[] C=new int[1500];
int i;
for(i=0; i<1500; i++)
{
A[i]=B[i]=C[i]=0;
}
A[0] = 2;
B[0] = 3;
C[0] = 5;
int ap,bp,cp; //比较到的头号
ap=bp=cp=0;
int at,bt,ct;
at=bt=ct=0; //生成的尾号
int count=1;
while(count < 1500)
{
if(A[ap]<B[bp]&&A[ap]<C[cp])
{
at++;
A[at]=2*A[ap];
bt++;
B[bt]=3*A[ap];
ct++;
C[ct]=5*A[ap];
Console.Write(count+": "+A[ap]+" ");
ap++;
}
else if(B[bp]<C[cp]&&B[bp]<A[ap])
{
bt++;
B[bt]=3*B[bp];
ct++;
C[ct]=5*B[bp];
Console.Write(count+": "+B[bp]+" ");
bp++;
}
else if(C[cp]<B[bp]&&C[cp]<A[ap])
{
ct++;
C[ct]=5*C[cp];
Console.Write(count+": "+C[cp]+" ");
cp++;
}
count++;
}
//
// TODO: 在此处添加代码以启动应用程序
//
}
}
}
--
*
* *
* *
no more to say
★ just wish you ★
good luck
※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.1.50]
[回到开始]
[上一篇][下一篇]
荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店