HDU 1058(打表)
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1058
Humble Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 29253 Accepted Submission(s): 12809
Write a program to find and print the nth element in this sequence
#include<bits/stdc++.h>
#define max_v 5850
int i2=1,i3=1,i5=1,i7=1,i;
int a[max_v];
using namespace std;
int f()
{
int x=min ( min ( 2*a[i2], 3*a[i3] ),
min ( 5*a[i5], 7*a[i7] ) );
if(x==2*a[i2])
{
++i2;
}else if(x==3*a[i3])
{
++i3;
}else if(x==5*a[i5])
{
++i5;
}else if(x==7*a[i7])
{
++i7;
}
return x;
}
int main()
{
a[0]=0;
a[1]=1;
for(i=2;i<max_v;i++)
{
a[i]=f();
if(a[i]==a[i-1])
{
i--;
}
}
int n;
while(~scanf("%d",&n))
{
if(n==0)
break;
printf("The %d",n);
if(n%100==11||n%100==12||n%100==13)
{
printf("th ");
}else if(n%10==1)
{
printf("st ");
}else if(n%10==2)
{
printf("nd ");
}else if(n%10==3)
{
printf("rd ");
}else
{
printf("th ");
}
printf("humble number is %d.\n",a[n]);
}
return 0;
}
HDU 1058(打表)的更多相关文章
- 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(离线打表)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1058 解题报告:输入一个n,输出第n个质因子只有2,3,5,7的数. 用了离线打表,因为n最大只有58 ...
- hdu 4542 打表+含k个约数最小数
http://acm.hdu.edu.cn/showproblem.php?pid=4542 给出一个数K和两个操作 如果操作是0,就求出一个最小的正整数X,满足X的约数个数为K. 如果操作是1,就求 ...
- HDU 1223 打表 + 大数
http://acm.hdu.edu.cn/showproblem.php?pid=1223 一般遇到这些题,我都是暴力输出前几项,找规律.未果. 然后输出n = 1时候,以A开始,有多少个答案, n ...
- hdu 1058 Humble Numbers
这题应该是用dp来做的吧,但一时不想思考了,写了个很暴力的,类似模拟打表,然后排序即可,要注意的是输出的格式,在这里wa了一发,看了别人的代码才知道哪些情况没考虑到. #include<cstd ...
- hdu 3652 打表
思路:直接打表 #include<cstdio> #include<vector> #include<cmath> #include<iostream> ...
- hdu 5183 hash表
BC # 32 1002 题意:给出一个数组 a 和一个数 K ,问是否存在数对( i , j ),使 a i - a i + 1 +……+ (-1)j - i a j : 对于这道题,一开始就 ...
- hdu 4715(打表)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4715 思路:先打个素数表,然后判断一下就可以了. #include<iostream> # ...
随机推荐
- React+antd 在限制高度内实现滚动显示多个组件(show scrolled components in a limited height with react antd)
效果: 代码: import React from 'react'; import { Table } from 'antd'; import DatePicker1 from './DatePick ...
- js原生日历
突然发现日期对象可以进行 加减 , 利用这个特性写了一个可以说是对只要会JavaScript 的就可以写的日历:没有各种算法,只有一些逻辑相信只要懂javascript就差不多看俩眼就会的日历. & ...
- 【Win32】对指定进程进行禁音
使用例子如下: CAudioMgr AudioMgr; AudioMgr.SetProcessMute(GetCurrentProcessId()); H文件的内容如下: #pragma once # ...
- APM飞控系统详细介绍
APM飞控系统详细介绍2013-04-05 12:28:24 来源: 评论:2 点击:10303 APM飞控系统是国外的一个开源飞控系统,能够支持固定翼,直升机,3轴,4轴,6轴飞行器.在此我 ...
- 关于App的cpu/内存/流量 /电量的方法(GT工具)
https://mp.weixin.qq.com/s?__biz=MzUzNTQxMzMzMg==&mid=2247484376&idx=1&sn=651e9cf22801b5 ...
- 提示"libc.so.6: version `GLIBC_2.14' not found"
启动php 提示"libc.so.6: version `GLIBC_2.14' not found",原因可能是glibc版本太低,php使用了较高的glibc版本引起的 1,首 ...
- Python 爬虫 获取标签下面的子标签
thr_msgs = soup.find_all('div',class_=re.compile('msg')) for i in thr_msgs: print(i) first = i.selec ...
- 初始python(一)
一.python特性概要 1. python是解释性脚本语言. 2. python特性总结 2.1 字节码 2.2 动态语义 在赋值是确定数据类型 2.3 缩进(4个空格) 3. python定义编码 ...
- December 05th 2016 Week 50th Monday
Today is my birthday and I have totally refreshed. Knowing yourself is the beginning of all wisdom. ...
- php中的html元素
我们先看下面的代码 form2.php <html> <head><title>greetins eartyling</title></head& ...