Humble Numbers HDU - 1058
Write a program to find and print the nth element in this sequence
InputThe input consists of one or more test cases. Each test case consists of one integer n with 1 <= n <= 5842. Input is terminated by a value of zero (0) for n.
OutputFor each test case, print one line saying "The nth humble number is number.". Depending on the value of n, the correct suffix "st", "nd", "rd", or "th" for the ordinal number nth has to be used like it is shown in the sample output.
Sample Input
1
2
3
4
11
12
13
21
22
23
100
1000
5842
0
Sample Output
The 1st humble number is 1.
The 2nd humble number is 2.
The 3rd humble number is 3.
The 4th humble number is 4.
The 11th humble number is 12.
The 12th humble number is 14.
The 13th humble number is 15.
The 21st humble number is 28.
The 22nd humble number is 30.
The 23rd humble number is 32.
The 100th humble number is 450.
The 1000th humble number is 385875.
The 5842nd humble number is 2000000000. 丑数
dp[i]=min(min(dp[a]*2,dp[d]*7),min(dp[b]*3,dp[c]*5));
if(dp[i]==dp[a]*2) a++;
if(dp[i]==dp[b]*3) b++;
if(dp[i]==dp[c]*5) c++;
if(dp[i]==dp[d]*7) d++;
输出的时候 注意13 12 11
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int dp[];
int main()
{
dp[]=;
int a=,b=,c=,d=;
for(int i=;i<=;i++)
{
dp[i]=min(min(dp[a]*,dp[d]*),min(dp[b]*,dp[c]*));
if(dp[i]==dp[a]*) a++;
if(dp[i]==dp[b]*) b++;
if(dp[i]==dp[c]*) c++;
if(dp[i]==dp[d]*) d++; }
int n;
while(~scanf("%d",&n)&&n)
{
if(n%==&&n%!=)
printf("The %dst humble number is %d.\n",n,dp[n]);
else if(n%==&&n%!=)
printf("The %dnd humble number is %d.\n",n,dp[n]);
else if(n%==&&n%!=)
printf("The %drd humble number is %d.\n",n,dp[n]);
else
printf("The %dth humble number is %d.\n",n,dp[n]); } return ;
}
Humble Numbers HDU - 1058的更多相关文章
- Humble Numbers HDU - 1058 2分dp
JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two ...
- hdu 1058 dp.Humble Numbers
Humble Numbers Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Subm ...
- HDOJ(HDU).1058 Humble Numbers (DP)
HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2 ...
- HDU 1058 Humble Numbers (DP)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu 1058:Humble Numbers(动态规划 DP)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1058 Humble Numbers (动规+寻找丑数问题)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU - The number of divisors(约数) about Humble Numbers
Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence ...
- HDU 1058 Humble Number
Humble Number Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humbl ...
- HDOJ 1058 Humble Numbers(打表过)
Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The ...
随机推荐
- 51nod 1069 Nim游戏 + BZOJ 1022: [SHOI2008]小约翰的游戏John(Nim游戏和Anti-Nim游戏)
首先,51nod的那道题就是最简单的尼姆博弈问题. 尼姆博弈主要就是判断奇异局势,现在我们就假设有三个石子堆,最简单的(0,n,n)就是一个奇异局势,因为无论先手怎么拿,后手总是可以在另一堆里拿走相同 ...
- jenkins+ant+jmeter自动化性能测试平台
jenkins+ant+jmeter自动化性能测试平台 Jmeter是性能测试的工具,java编写.开源,小巧方便,可以图形界面运行也可以在命令行下运行.网上已经有人使用ant来运行,http://w ...
- 如何判断一个js对象是否是Array
经常遇到一个问题,判断某个对象是否为数组类型,在Js中检测对象类型的常见方式有以下: typeof操作符 对于Function.String.Number.Undefined等几种类型的对象来说,几乎 ...
- Spring-MVC依赖
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api& ...
- 【五】php 面向对象
面向对象 概念:按类进行分类,类是表示彼此之间可能互不相同,但是具有一些共同点的对象集合 多态性:不同的类对同一操作可以有不同的行为 继承:允许我们使用子类在类之间创建层次关系 类 关键字:class ...
- 如何用git把本地代码上传到github
注册账户以及创建仓库 要想使用github第一步当然是注册github账号了.之后就可以创建仓库了(免费用户只能建公共仓库),Create a New Repository,填好名称后Create,之 ...
- 一篇很好的java异常框架讲解
https://www.cnblogs.com/itcui/p/6400499.html 其实原作者是csdn的一名博主,实在受不了csdn的广告,所以就摘录这篇
- linux学习笔记--程序与进程管理
.工作管理 1.前台程序放后台程序 命令后 加 & 2.任务执行时将前台任务任务放到后台中并[暂停] ctr + z 3.jobs 观察后台工作状态 及多少任务在执行,可以通过 help ...
- Eclipse中使用MySql遇到:Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading o
在Eclipse中使用MySQL遇到了点小问题 如果对Eclipse中配置MySql还有疑问的可以参考一下这篇博客:https://blog.csdn.net/qq_38247544/article/ ...
- DAY1 计算机组成和操作系统
一.编程与编程目的 1.编程语言的定义 编程语言是人与计算机之间沟通的介质 2.什么是编程 编程就是程序员通过编程语言让计算机实现所想做的事 3.编程的目的 解放人力,让计算机按照人的逻辑思维进行工作 ...