HDU 3199 Hamming Problem
Hamming Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1305 Accepted Submission(s): 583
Problem Description
For each three prime numbers p1, p2 and p3, let's define Hamming sequence Hi(p1, p2, p3), i=1, ... as containing in increasing order all the natural numbers whose only prime divisors are p1, p2 or p3.
For example, H(2, 3, 5) = 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, ...
So H5(2, 3, 5)=6.
Input
In the single line of input file there are space-separated integers p1 p2 p3 i.
Output
The output file must contain the single integer - Hi(p1, p2, p3). All numbers in input and output are less than 10^18.
Sample Input
7 13 19 100
Sample Output
26590291
Source
Northeastern Europe 2000 - Far-Eastern Subregion
解析:本题是[HDU 1058 Humble Numbers](http://www.cnblogs.com/inmoonlight/p/6030949.html)的升级版,2、3、5变成了p1、p2、p3。不过原理是相同的,都是运用DP的思想。因为题目有说明所有输入输出小于10^18,我们可以用2、3、5来得到最大可能出现的下标。经过测试,第一个大于或等于10^18的数下标为10916,因而数组的大小最小为10917。
```
#include
#include
#define ll long long
using namespace std;
ll res[11000];
void solve(int a, int b, int c, int n)
{
res[0] = 1;
int p1 = 0, p2 = 0, p3 = 0;
for(int i = 1; i <= n; ++i){
res[i] = min(res[p1]a, min(res[p2]b, res[p3]c));
if(res[i] == res[p1]a) ++p1;
if(res[i] == res[p2]b) ++p2;
if(res[i] == res[p3]c) ++p3;
}
printf("%I64d\n", res[n]);
}
int main()
{
int a, b, c, n;
while(~scanf("%d%d%d%d", &a, &b, &c, &n)){
solve(a, b, c, n);
}
return 0;
}
HDU 3199 Hamming Problem的更多相关文章
- hdu 3199 Hamming Problem(构造?枚举?)
题意: For each three prime numbers p1, p2 and p3, let's define Hamming sequence Hi(p1, p2, p3), i=1, . ...
- Hamming Problem(hdu3199)
Hamming Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 3549 Flow Problem(最大流)
HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- hdu 5106 Bits Problem(数位dp)
题目链接:hdu 5106 Bits Problem 题目大意:给定n和r,要求算出[0,r)之间全部n-onebit数的和. 解题思路:数位dp,一个ct表示个数,dp表示和,然后就剩下普通的数位d ...
- HDU 3374 String Problem (KMP+最大最小表示)
HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu 5105 Math Problem(数学)
pid=5105" target="_blank" style="">题目链接:hdu 5105 Math Problem 题目大意:给定a.b ...
- Hdu 5445 Food Problem (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online)
题目链接: Hdu 5445 Food Problem 题目描述: 有n种甜点,每种都有三个属性(能量,空间,数目),有m辆卡车,每种都有是三个属性(空间,花费,数目).问至少运输p能量的甜点,花费 ...
- 网络流 HDU 3549 Flow Problem
网络流 HDU 3549 Flow Problem 题目:pid=3549">http://acm.hdu.edu.cn/showproblem.php?pid=3549 用增广路算法 ...
- hdu 4712 Hamming Distance(随机函数暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
随机推荐
- 转:关于安卓多线程while(true)方法占用CPU高的原因及其解决方法
由于项目需要用到安卓多线程操作,结果开了四条线程,下载到平板一直很卡,CPU占用率暴涨.于是开始查找原因,发现是线程run()方法里的while(true)导致的, 下图是为解决时开启一条while( ...
- iOS开发UITableViewCell的选中时的颜色设置(转)
iOS开发UITableViewCell的选中时的颜色设置 1.系统默认的颜色设置 //无色 cell.selectionStyle = UITableViewCellSelectionStyle ...
- You don't have permission to access javascript on this server
今天访问遇到一个很奇怪的问题,在本地测试 http://localhost:9012/javascript/, 报错: Forbidden You don't have permission to a ...
- Ubuntu下创建JerBrains系列软件的快捷方式
以pycharm为例: 终端输入:sudo gedit /usr/share/applications/Pycharm.desktop模板: [Desktop Entry]Type=Applicati ...
- python 模块中__all__作用
test.py文件开头写上__all__=[func1,func2] 当其他文件导入 from test import * 只会导出"[func1,func2]"里面的,其他调用 ...
- Python 爬虫实战2 百度贴吧帖子
爬取百度贴吧的帖子.与上一篇不同的是,这次我们需要用到文件的相关操作. 本篇目标 对百度贴吧的任意帖子进行抓取 指定是否只抓取楼主发帖内容 将抓取到的内容分析并保存到文件 1.URL格式的确定 首先, ...
- Linux命令之umask
一 权限掩码umask umask是chmod配套的,总共为4位(gid/uid,属主,组权,其它用户的权限),不过通常用到的是后3个,例如你用chmod 755 file(此时这文件的权限是属主读( ...
- 一个智障安装了一天的python和graphlab的血泪史
大概的过程是这样的: 先装了python3.6.1.,然后发现搞错了Σ(  ̄□ ̄||),是32 bit的,卸了重装python 3.6.1 (64bit). 然后装easy_install.pip.i ...
- 《从零开始学Swift》学习笔记(Day 23)——尾随闭包
原创文章,欢迎转载.转载请注明:关东升的博客 闭包表达式可以作为函数的参数传递,如果闭包表达式很长,就会影响程序的可读性.尾随闭包是一个书写在函数括号之后的闭包表达式,函数支持将其作为最后一个参数调用 ...
- 1282 时钟(最小表示法+hash)
1282 时钟 题目来源: Codility 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 有N个时钟,每个时钟有M个指针,P个刻度.时钟是圆形的,P个刻度均分整 ...