Save Princess

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
 
描述
Yesterday, the princess was kidnapped by a devil. The prince has to rescue our pretty princess.
 
"OK, if you want to save the beautiful princess, you must answer my questions correctly."the devil says.
 
"No problem!".
 
"I’ll ask you t questions. For each question, I’ll tell you an integer n, you must tell me the i th beatuiful number. If your answer is wrong, the princess and you will all die".
 
"But what is the characteristic of the beautiful number?" Pince asks.
 
"Beautiful numbers are numbers whose only prime factors are 2, 3 or 5. The sequence
1, 2, 3, 4, 5, 6, 8, 9, 10, ...   shows the first 9 beautiful numbers. 
By convention, 1 is included. "
 
Can you help the prince to save the princess?
 
输入
The input for each case is an integer n(1≤n≤5000) and it is terminated by a negative integer.
输出
For each test case, you should print an integer which represents the i th beautiful number.
样例输入
2
3
-1
样例输出
2
3

题解:这个方法解决丑数非常实用;

代码:

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN=;
typedef long long LL;
LL ans[MAXN];
LL MIN(LL x,LL y,LL z){
LL d=x;
if(y<d)d=y;
if(z<d)d=z;
return d;
}
int main(){
int n,x_2=,x_3=,x_5=;
LL d;
ans[]=;
int i=;
while(i<=){
i++;
d=MIN(ans[x_2]*,ans[x_3]*,ans[x_5]*);
ans[i]=d;
if(d==ans[x_2]*)x_2++;
if(d==ans[x_3]*)x_3++;
if(d==ans[x_5]*)x_5++;
}
while(scanf("%d",&n),n>)printf("%lld\n",ans[n]);
return ;
}

Save Princess(丑数)的更多相关文章

  1. nyoj1032——Save Princess——————【set应用】

    Save Princess 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Yesterday, the princess was kidnapped by a de ...

  2. AC日记——丑数 codevs 1246

    1246 丑数 USACO  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 对于一给定的素 ...

  3. 剑指Offer面试题:29.丑数

    一.题目:丑数 题目:我们把只包含因子2.3和5的数称作丑数(Ugly Number).求按从小到大的顺序的第1500个丑数.例如6.8都是丑数,但14不是,因为它包含因子7.习惯上我们把1当做第一个 ...

  4. 剑指Offer:面试题34——丑数(java实现)

    问题描述: 把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N个丑数. 思路1: ...

  5. UVA136 求第1500个丑数

    枚举大范围数据..暴力检查题目条件 #include <iostream> #include <cstdio> #include <vector> #include ...

  6. 37.寻找丑数[Ugly numbers]

    [题目] 我们把只包含质因子2.3和5的数称作丑数(Ugly Number),例如:2,3,4,5,6,8,9,10,12,15,等,习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第1500个丑 ...

  7. hdu1058丑数(优先队列、暴力打表)

    hdu1058 题意:当一个数只有2.3.5.7这四种质因数时(也可以一种都没有或只有其中几种),这个数就是丑数,输出第 n 个丑数是多少: 其实并没有发现hdu把这道题放在 dp 专题里的意图,我的 ...

  8. 剑指offer系列59---寻找丑数

    [题目]把只包含因子2.3和5的数称作丑数(Ugly Number). * 例如6.8都是丑数,但14不是,因为它包含因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N个丑数. 解法一 ...

  9. 洛谷P2723 丑数 Humble Numbers

    P2723 丑数 Humble Numbers 52通过 138提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 题目背景 对于一给定的素数 ...

随机推荐

  1. Gridview编辑时Jquery自动计算自定义列(鼠标离开输入框Jquery计算)

    Jquery片段: <script type="text/javascript"> function compute(nbBoxQuantity, lblQuantit ...

  2. DIV+CSS解决IE6,IE7,IE8,FF兼容问题(转至http://www.douban.com/note/163291324/)

    2011-07-25 21:11:47     DIV+CSS解决IE6,IE7,IE8,FF兼容问题 1.IE8下兼容问题,这个最好处理,转化成IE7兼容就可以.在头部加如下一段代码,然后只要在IE ...

  3. objective-C学习笔记(五)函数成员:初始化器和析构器

    初始化器:init 对象初始化器: -(id)init 可以重载多个. 类型初始化器: +(id)initialize只能有一个. 对象初始化器: 初始化对象实例时,init通常和alloc(手动内存 ...

  4. DataSet中取值(转)

    1 DataSet.Table[0].Rows[ i ][ j ] 其中i 代表第 i 行数, j 代表第 j 列数 2 DataSet.Table[0].Rows[ i ].ItemArray[ j ...

  5. 如何修改MFC发布程序的图标

    (1)第一种方法,直接替换工程路径下面res下面的ico图标,然后重新编译,一般需要重启系统才会生效: (2)第二种方法,在VS工程资源预览窗口的ICO下增加一个ico资源,名为IDR_ICON1,然 ...

  6. C++中引用

    在C语言中&这个符号表示了取地址符,但是在C++中它却有着不同的用途,掌握C++的&符号,是提高代码执行效率和增强代码质量的一个很好的办法.一.引用简介 引用就是某一变量(目标)的一个 ...

  7. Mac搭建Java开发环境

    参考博文: http://shupeng.org/2012/10/14/config-java-env-on-mac/ http://hdu104.com/23 注意事项: (Mac OS X - M ...

  8. Linux 网络编程: xinetd time

    前言 终于把 xinetd 服务装好了,那就在来实现一下 TCP 协议从服务器和本机获取时间吧.那么多思想汇报还没写,我也是醉了. 安装 xinetd apt-get install xinetd 配 ...

  9. 名叫Florida的女孩问题

    近读列纳德·蒙洛迪诺的<醉汉的脚步>,读到第六章,作者举了一个超级变态的例子来解释条件概率或者说是贝叶斯概率. 1.先来看一个简单点的问题:已知所有有2个孩子的家庭,其中一个家庭2个孩子都 ...

  10. css3: css3选择器

    --------------------css3选择器-------------------------css3属性选择器  ~~属性选择器基本上ie7+都支持,可以相对放心的使用 见: www.ca ...