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 ...
随机推荐
- HDU 5844 LCM Walk(数学逆推)
http://acm.hdu.edu.cn/showproblem.php?pid=5584 题意: 现在有坐标(x,y),设它们的最小公倍数为k,接下来可以移动到(x+k,y)或者(x,y+k).现 ...
- Linux命令去重统计排序
利用Linux命令进行文本按行去重并按重复次数排序 linux命令行提供了非常强大的文本处理功能,组合利用linux命令能实现好多强大的功能.本文这里举例说明如何利用Linux命令行进行文本按行去 ...
- phpstorm软件配置端口问题
phpstorm默认的端口号是:63342 但是我装的apache服务器的默认端口是80 网上查找资料,都说可以加listen的端口,比如这里 #Listen 12.34.56.78:80 Lis ...
- EditText取消焦点
EditText取消焦点: 在父容器添加: android:focusable="true" android:focusableInTouchMode="true&quo ...
- 力扣(LeetCode)709. 转换成小写字母
实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串. 示例 1: 输入: "Hello" 输出: & ...
- 餐E评echarts
所需要的数据结构 option = { num:1212,//商圈数 numRate:34%,//商圈增长率 activation:1231,//活跃度 activationRate:23%,//活跃 ...
- C#清除HTML样式
C#清除HTML样式 需求说明: 网站开发时我们经常用一个富文本控件让用户自己编辑新闻内容和新闻格式,然后将HTML代码一并保存到数据库中. 然后显示文章列表的时候只需要显示一个文章摘要,所以我们就计 ...
- HeadFirst Ruby 第七章总结 references
前言 这一章的内容关于 references,讲了当 Ruby 程序中可能会遇到关于 reference 与 object 之间概念混淆而导致的问题. 导言 本章从一个 astronomer 发现 s ...
- 雷林鹏分享:jQuery EasyUI 表单 - 格式化下拉框
jQuery EasyUI 表单 - 格式化下拉框 本教程向您展示如何创建一个简单的下拉框(Combobox),让它在下拉框中显示图片项.您可以在下拉框(combobox)上使用 formatter ...
- fMRI在认知心理学上的研究
参考:Principles of fMRI 1 问题: 1. fMRI能做什么不能做什么? 第一周:fMRI简介,data acquisition and reconstruction 大致分为两类: ...