HDU 1058 Humble Numbers (DP)
Humble Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18238 Accepted Submission(s): 7934
Write a program to find and print the nth element in this sequence
2
3
4
11
12
13
21
22
23
100
1000
5842
0
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有点牵强,不过也算是用前面的状态推出后面的状态,英语知识是个易错点。
思路:2,5,7,9是丑数,丑数的2,5,7,9倍也是丑数,所以从1开始,对每个数计算计算它的2,5,7,9倍,算出来的结果又再翻倍。难免会遇到这种考察其它乱七八糟的知识点的题,输出时的后缀很容易错,在英语里如果一个数的个位是1,那后面跟st,2跟nd,3跟rd,其它跟th,但是注意,后面两位是11,12,13的除外,这些数后面都跟th,比如12,10013,1111,我WA了三次,算是英语差的后果吧。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 5845 int my_min(int a,int b,int c,int d);
int main(void)
{
int n;
int s[MAX] = {};
int i,i_2,i_3,i_5,i_7;
int box,box_2,box_3,box_5,box_7;
char cha[];
i = i_2 = i_3 = i_5 = i_7 = ; while(i < MAX - )
{
box_2 = s[i_2] * ;
box_3 = s[i_3] * ;
box_5 = s[i_5] * ;
box_7 = s[i_7] * ; box = my_min(box_2,box_3,box_5,box_7); //每次把最小的那个插入到数组里,就不用排序了
if(box == box_2) //要一直用if,因为结果可能相同
i_2 ++;
if(box == box_3)
i_3 ++;
if(box == box_5)
i_5 ++;
if(box == box_7)
i_7 ++; i ++;
s[i] = box;
} while(scanf("%d",&n) && n)
{
box = n % ;
if(box == || box == || box == )
{
strcpy(cha,"th");
goto label;
} box = n;
while(box / )
box %= ;
switch(box % )
{
case :strcpy(cha,"st");break;
case :strcpy(cha,"nd");break;
case :strcpy(cha,"rd");break;
default :strcpy(cha,"th");break;
} label:
printf("The %d%s humble number is %d.\n",n,cha,s[n - ]);
} return ;
} int my_min(int a,int b,int c,int d)
{
int min = a; min = min < b ? min : b;
min = min < c ? min : c;
min = min < d ? min : d; return min;
}
HDU 1058 Humble Numbers (DP)的更多相关文章
- 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 (动规+寻找丑数问题)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU 1058 Humble Numbers【DP】
题意:给出丑数的定义,只含有2,3,5,7这四个素数因子的数称为素数.求第n个丑数. 可以先观察几个丑数得出规律 1:dp[1] 2:min(1*2,1*3,1*5,1*7) 3:min(2*2,1* ...
- HDU 1058 Humble Numbers(离线打表)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1058 解题报告:输入一个n,输出第n个质因子只有2,3,5,7的数. 用了离线打表,因为n最大只有58 ...
- hdu 1058 Humble Numbers
这题应该是用dp来做的吧,但一时不想思考了,写了个很暴力的,类似模拟打表,然后排序即可,要注意的是输出的格式,在这里wa了一发,看了别人的代码才知道哪些情况没考虑到. #include<cstd ...
- hdu 1058 Humble Numbers(构造?枚举?)
题意: 一个数的质因子如果只是2,3,5,7中的若干个.则这个数叫做humble number. 例如:1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 1 ...
- [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 ...
- HDU 1058 Humble Number
Humble Number Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humbl ...
随机推荐
- 第二百六十八天 how can I坚持
早上看了个电影<我的少女时代>,挺好看的. 下午从四点玩游戏一直玩到现在,也是疯了. 晚上也没有吃饭,是不是太堕落了. 徐斌他同学今天中午过来,做了个饭,也是服了,好难吃. 还没做好准备, ...
- 软件工程——PairProject
结对编程组员: 马辰 11061178 柴泽华 11061153 1) 照至少一张照片, 展现两人在一起合作编程的情况. 结对编程的优点 1)在编程过程中,任何一段代码都不断地复审,同 ...
- HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)
NanoApe Loves Sequence Ⅱ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5806 Description NanoApe, t ...
- jdk的wsimport方法实现webservice客户端调用服务
1.配置好jdk环境,打开命令行,输入wsimport回车能看到很多该命令的参数, -s:要生成客户端代码的存储路径 -p:对生成的代码从新打包 这两个最常用. 在打开的命令行中输入:wsimport ...
- HDU 5768 Lucky7 (中国剩余定理+容斥)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5768 给你n个同余方程组,然后给你l,r,问你l,r中有多少数%7=0且%ai != bi. 比较明显 ...
- 命令行刷机教程( 以Linux系统为例 )
//第一步adb device // 如果不能cd AndroidSDK/platform-toolsadb kill-server adb start-server //第二步adb reboot ...
- UVA 11134 - Fabled Rooks(贪心+优先队列)
We would like to place n rooks, 1 ≤ n ≤ 5000, on a n×n board subject to the following restrict ...
- 如何在Android中使用OpenCV
如何在Android中使用OpenCV 2011-09-21 10:22:35 标签:Android 移动开发 JNI OpenCV NDK 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始 ...
- android 多线程数据库读写分析与优化
最新需要给软件做数据库读写方面的优化,之前无论读写,都是用一个 SQLiteOpenHelper.getWriteableDataBase() 来操作数据库,现在需要多线程并发读写,项目用的是2.2的 ...
- Tomcat7集群扩展session集中管理,tomcat-redis-session-manager使用
请参考官方文档 下载所需的包了: tomcat-redis-session-manager-1.1.jar jedis-2.1.0.jar commons-pool-1.6.jar 将这些jar包都丢 ...