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. 如何:打开 IIS 管理器

    大家好,我叫李京阳,,很高兴认识大家,因为最近我发现很多朋友连打开IIS管理都不知道,可能也是因为各个系统的版本不同,所以今天发一简单贴说说打开IIS管理器. 启动 IIS 7.0 的 IIS 管理器 ...

  2. JS提取URL中的参数

    <!DOCTYPE html><html>    <head>        <meta charset="UTF-8">      ...

  3. 委托与Lambda表达式

    ~,先不急说委托和Lambda表达式,先看两个例子再说: 1. 通过委托,为一个数字加10,如下代码: class Program { private delegate int JiSuan(int ...

  4. Ubuntu_16.04_Lamp

    Ubuntu_16.04安装Lamp开发环境 目录 安装Apache2 安装php5 安装mysql-server 安装php5-mysql(php使用mysql服务,包括mysql,mysqli,m ...

  5. Determine If Two Rectangles Overlap

    判断相交的情况比较复杂,所以从判断不相交的角度考虑. ! (P1.y < P4.y || P1.x > P4.x || P2.y > P3.y || P2.x < P3.x)

  6. Problem A: 走迷宫问题

    Problem A: 走迷宫问题Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 9 Solved: 3[Submit][Status][Web Board] ...

  7. gridview回顾

    第一看asp.net是在做项目之前,感觉收获也很大,第二次看gridview是在做完项目之后对GridView的回顾,这次的感觉是:我需要多想点,知识直到用时方觉少.直入正题吧,看gridview. ...

  8. PHP获取网址的PR值

    PR值是google衡量网站的重要标准之一,根据google提供的结果获取pr值,如:http://toolbarqueries.google.com.hk/tbr?client=navclient- ...

  9. Bootstrap dropdown 使用

    同样是2种方式 参考http://www.bootcss.com/javascript.html#dropdowns JS方式调用 http://www.w3resource.com/twitter- ...

  10. Nginx工作原理和优化、漏洞(转)

    查看安装了哪些模块命令: [root@RG-PowerCache-X xcache]# nginx/sbin/nginx -Vnginx version: nginx/1.2.3built by gc ...