HDU——1058Humble Numbers(找规律)
Humble Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 21853 Accepted Submission(s): 9553
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.
#include<iostream>
#include<set>
using namespace std;
typedef long long LL;
LL er=1,san=1,wu=1,qi=1;
LL minn(const LL &a,const LL &b,const LL &c,const LL &d)
{
LL t=a;
if(b<t)
t=b;
if(c<t)
t=c;
if(d<t)
t=d;
//下面都要用if而非else-if 出现重复的数时才可以多个数均被++
if(t==a)
er++;
if(t==b)
san++;
if(t==c)
wu++;
if(t==d)
qi++;
return t;
}
int main(void)
{
LL i;
LL list[5900]={1,1};
for (i=2; i<5900; i++)
{
list[i]=minn(2*list[er],3*list[san],5*list[wu],7*list[qi]);
}
int n;
while (cin>>n&&n)
{
if(n%10==1&&n%100!=11)
printf("The %dst humble number is %lld.\n",n,list[n]);
else if(n%10==2&&n%100!=12)
printf("The %dnd humble number is %lld.\n",n,list[n]);
else if(n%10==3&&n%100!=13)
printf("The %drd humble number is %lld.\n",n,list[n]);
else
printf("The %dth humble number is %lld.\n",n,list[n]);
}
return 0;
}
HDU——1058Humble Numbers(找规律)的更多相关文章
- HDU 2086 A1 = ? (找规律推导公式 + 水题)(Java版)
Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2086 ——每天在线,欢迎留言谈论. 题目大意: 有如下方程:Ai = (Ai-1 ...
- hdu 5047 大数找规律
http://acm.hdu.edu.cn/showproblem.php?pid=5047 找规律 信kuangbin,能AC #include <stdio.h> #include & ...
- SGU 169 Numbers (找规律)
题意:中文题,直接忽略... 析:先说说我的思路,我一看这个题第一感觉就是要找规律,要是挨着算,猴年马月都跑不完,更何况时间限制是0.25s,怎么找规律呢,我算了一下前10位,分别是8,1,1,3,1 ...
- SGU-169 Numbers(找规律)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=169 解题报告: P(n)定义为n的所有位数的乘积,例如P(1243)=1*2*3* ...
- hdu 5106 组合数学+找规律
http://acm.hdu.edu.cn/showproblem.php?pid=5106 给定n和r,要求算出[0,r)之间所有n-onebit数的和,n-onebit数是所有数位中1的个数. 对 ...
- URAL 2070 Interesting Numbers (找规律)
题意:在[L, R]之间求:x是个素数,因子个数是素数,同时满足两个条件,或者同时不满足两个条件的数的个数. 析:很明显所有的素数,因数都是2,是素数,所以我们只要算不是素数但因子是素数的数目就好,然 ...
- Doom HDU - 5239 (找规律+线段树)
题目链接: D - Doom HDU - 5239 题目大意:首先是T组测试样例,然后n个数,m次询问,然后每一次询问给你一个区间,问你这个这段区间的加上上一次的和是多少,查询完之后,这段区间里 ...
- hdu 4708(暴力+找规律)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 思路:由于N不大,并且我们可以发现通过旋转得到的4个对角线的点的位置关系,以及所要旋转的最小步数 ...
- hdu 4759 大数+找规律 ***
题目意思很简单. 就是洗牌,抽出奇数和偶数,要么奇数放前面,要么偶数放前面. 总共2^N张牌. 需要问的是,给了A X B Y 问经过若干洗牌后,第A个位置是X,第B个位置是Y 是不是可能的. Ja ...
随机推荐
- ABAP function group和Tomcat library重复加载问题
ABAP ABAP help文档里对**LOAD-OF-PROGRAM"的关键字是这样描述的: This event keyword defines the program construc ...
- HDU 4284 Travel (Folyd预处理+dfs暴搜)
题意:给你一些N个点,M条边,走每条边要花费金钱,然后给出其中必须访问的点,在这些点可以打工,但是需要先拿到证书,只可以打一次,也可以选择不打工之直接经过它.一个人从1号点出发,给出初始金钱,问你能不 ...
- Problem Q: C语言习题 计算该日在本年中是第几天
Problem Q: C语言习题 计算该日在本年中是第几天 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 4572 Solved: 2474[Subm ...
- ES6学习笔记(二)
Set 和 Map 数据结构 1.set 基本用法 ES6提供了新的数据结构Set,它类似于数组,但是成员的值都是唯一的,没有重复的值 Set本身是一个构造函数,用来生成Set数据结构 const s ...
- 2018.3.26 Linux下学习命令
Linux下的终端文件颜色说明 ---color[=WHEN] 用色彩辨别文件类型 WHEN 可以是'never'.'always'或'auto'其中之一 白色:表示普通文件 蓝色:表示目录 绿色:表 ...
- JavaScript实现页面到滚动到指定位置执行某些操作
比如 页面中 某个DOM, 希望点击按钮后页面直接跳转到 这个DOM所在的位置, 1. 获取DOM离屏幕的高度 var hTop = $('#box').offset().top; $('body,h ...
- java基础—网络编程
一.网络基础概念 首先理清一个概念:网络编程 != 网站编程,网络编程现在一般称为TCP/IP编程.
- sqlite3 数据库使用
首先,通过官网下载sqlite3.h和sqlite3.c两个文件,用于调用里面的api函数操作数据库. 这里也提供链接地址下载:http://pan.baidu.com/s/1qWzjqPY 其中里面 ...
- [译]The Python Tutorial#5. Data Structures
[译]The Python Tutorial#Data Structures 5.1 Data Structures 本章节详细介绍之前介绍过的一些内容,并且也会介绍一些新的内容. 5.1 More ...
- JdbcTemplate实验
实验1:测试数据源 @Test public void test() throws SQLException { ApplicationContext ioc = new ClassPathXmlAp ...