POJ1338 Ugly Numbers中英文对照翻译与参考解答

POJ1338是关于寻找丑陋数(仅由2, 3, 5的质因数构成)的问题。题目要求找到第n个丑陋数,输入范围是1到1500。解决策略是预先计算前1500个丑陋数,并使用最小的数进行递增。可以视为三个队列的同步操作。给出的参考代码用于实现这一逻辑。" 115955722,10542825,Matlab 插值技术详解:从最邻近到双三次,"['matlab', '图像处理', '插值算法']
摘要由CSDN通过智能技术生成

传送门: POJ1338
关键词: 枚举;队列;

这题目还是有很多值得品位的地方,思路上其实不是很容易想到。

Description

Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence
1, 2, 3, 4, 5, 6, 8, 9, 10, 12, …
shows the first 10 ugly numbers. By convention, 1 is included.
Given the integer n,write a program to find and print the n’th ugly number.

丑陋数(Ugly Number)是仅含有素因子2、3或5的整数。序列给出了前10个丑陋数。按照惯例,1被包含在丑陋数中。给出整数n,编写一个程序找出并打印第n个丑陋数。

Input

Each line of the input contains a postisive integer n (n <= 1500).Input is terminated by a line with n=0.

输入的每行给出一个正整数n(n<=1500)。输入以n=0的一行结束。

Output

For each line, output the n’th ugly number .:Don’t deal with the line with n=0.

对于输入的每一行,输出第n个丑陋数,对n=0的那一行不处理。

Sample Input

1
2
9
0

Sample Output

1
2
10

Source

New Zealand 1990 Division I,UVA 136

解析

  1. n <= 1500,可以采用离线求解的形式,先把前1500个ugly number计算并保存,之后需要那个,直接下标索引就可以了。
  2. 为了让生成的ugly number有序,每次选择最小的整数来递进(threeMin)。
  3. P.S. 实际上可以理解为三个队列。

参考代码


                
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值