humble number(hd1058)
Write
a program to find and print the nth element in this sequence
case consists of one integer n with 1 <= n <= 5842. Input is terminated by
a value of zero (0) for n.
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.
/*看题解AC的,结果开始开编译错误了几次,oj说是min()没定义,那为什么自己编译会通过,然后自己写了min(),dp方程 dp[i]=f[i]=min(f[a]*2,min(f[b]*3,min(f[c]*5,f[d]*7)))*/
#include<stdio.h>/*dev编译后运行程序中途闪退,提交后却对的*/
using namespace std;
int min(int a,int b)
{
return a>b?b:a;
}
int humble[];
void factor()/*马丹看了半天也是似懂非懂,比赛时完全想不出来这么求*/
{
int post1=,post2=,post3=,post4=,na,nb,nc,nd,i;
humble[]=;
for(i=;i<=;i++)
{
humble[i]=min(na=humble[post1]*,min(nb=humble[post2]*,min(nc=humble[post3]*,nd=humble[post4]*)));
if(humble[i]==na) post1++;
if(humble[i]==nb) post2++;
if(humble[i]==nc) post3++;
if(humble[i]==nd) post4++;
}
}
int main()
{
int n;
factor();
while(~scanf("%d",&n))
{
if(n==)
break;
printf("The %d",n);
if(n%!=&&n%==)
printf("st");
else if(n%!=&&n%==)
printf("nd");
else if(n%!=&&n%==)
printf("rd");
else
printf("th");
printf(" humble number is %d.\n",humble[n]);
}
}
humble number(hd1058)的更多相关文章
- HDU 1058 Humble Number
Humble Number Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humbl ...
- HDU Problem D [ Humble number ]——基础DP丑数序列
Problem D Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submi ...
- 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 ...
- The number of divisors(约数) about Humble Numbers[HDU1492]
The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- The number of divisors(约数) about Humble Numbers
The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- HDU1492/The number of divisors(约数) about Humble Numbers
题目连接 The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- HDUOJ---The number of divisors(约数) about Humble Numbers
The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- HDU-1492-The number of divisors(约数) about Humble Numbers -求因子总数+唯一分解定理的变形
A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, ...
- [poj2247] Humble Numbers (DP水题)
DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...
随机推荐
- 那些我希望在一开始使用 Zsh(oh-my-zsh) 时就知道的
原文地址:http://segmentfault.com/a/1190000002658335 作者:xavier 自带的插件 其实我用了 oh-my-zsh 快三个月后才知道原来他自带了很多插件没 ...
- js 创建对象
1.工厂模式 function createPerson(name, age, job) { var o = new Object(); o.name = name; o.age = age; o.j ...
- GitHub好站点
https://github.com/XingCloud/stream_processor
- QTableView使用HTML显示富文本
对于QTableView中的显示,我们前面介绍过很多种,其中包括:文本.进度条.复选框等,今天我们介绍一下关于富文本的显示. 可能绝大多数小伙伴会通过QAbstractTableModel中的data ...
- 用VS2013+VELT-0.1.4进行海思平台 Linux内核 的开发
快乐虾 http://blog.csdn.net/lights_joy/(QQ群:Visual EmbedLinux Tools 375515651) 欢迎转载,但请保留作者信息 本文仅适用于vs20 ...
- C#中Split分隔字符串的应用(C#、split、分隔、字符串)
转载地址 .用字符串分隔: using System.Text.RegularExpressions; string str="aaajsbbbjsccc"; string[] s ...
- C语言简单strcat和strcmp的实现
对于C标准库中的字符串处理函数应该平常用的比较多:简单实现strcat和strcmp _strcpy: char *_strcpy(char *dest, char *src) { char *buf ...
- Word Ladder II 解答
Question Given two words (beginWord and endWord), and a dictionary's word list, find all shortest tr ...
- Isomorphic Strings 解答
Question Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if ...
- 【LeetCode练习题】Swap Nodes in Pairs
Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For exam ...