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. TCP各种连接状态注释

    TCP各种连接状态注释  连接进程是通过一系列状态表示的,这些状态有:LISTEN,SYN-SENT,SYN-RECEIVED,ESTABLISHED,FIN-WAIT-1,FIN-WAIT-2,CL ...

  2. iOS:将NSDate转换为当前时区时间

     NSDate *date = [NSDate date]; NSTimeZone *zone = [NSTimeZone systemTimeZone]; NSInteger interval = ...

  3. ELK(ElasticSearch, Logstash, Log4j)系统日志搭建

    1.elk平台介绍 Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等. Logsta ...

  4. mysql 创建表字段类型笔记

    1.字段联合唯一,unique(ServerVersion , MobileVersion, MobileType) .并且mysql设置多个字段为主键是起不到约束唯一的作用. 2.二进制用 BLOB ...

  5. java 无法割符日期字符串转yyyy-MM-dd hh:mm:ss

    1.需要转换字符串(20150210125942),转化后要达到的目的:2015-02-10 12:59:42 public static void main(String[] args) { Str ...

  6. datatable,查询,排序,复制等操作

    DataTable排序,检索,合并详解 一.排序 获取DataTable的默认视图 对视图设置排序表达式 用排序后的视图导出的新DataTable替换就DataTable (Asc升序可省略,多列排序 ...

  7. IOS 学习笔记(2) 视图UINavigationController

    1.栈 导航控制器自身有一个针对显示内容的栈,也有一个对于导航栏的栈,当有新的内容欲显示时,进的导航栏和显示内容会被压入此栈,这样原本显示中的导航栏和显示内容则会进入到栈的更深一层中,根据栈的先进后出 ...

  8. 定时每天备份mysql

    http://blog.csdn.net/panning_hu/article/details/9210001 Spring MVC Spring中MVC框架的底层实现 http://blog.csd ...

  9. angulajs 当input使用 bootstrap的email类型时,如果是无效的email格式,则ng-model无效的情况

    当使用bootstrap的如下input时 <input type="email" ng-model="userid"> 如果输入的内容是无效的em ...

  10. Hibernate 知识提高

    主键生成策略有: UUID,increment.Hilo.assigned:对数据库无依赖 identity:依赖Mysql或sql server,主键值不由hibernate维护 sequence: ...