zoukankan      html  css  js  c++  java
  • 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 ", 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;
    }

  • 相关阅读:
    Bash的提示符
    小笨霖英语笔记本(5)
    什么是VLAN
    阅读笔记:双核心Opteron处理器
    小笨霖英语笔记本(4)
    搭乘CCNUMA快车
    得到tnsnames.ora文件的位置 zz
    关于64位Windows操作系统中的注册表 zz
    Temp.Misc
    HttpHandler HttpModule入门篇
  • 原文地址:https://www.cnblogs.com/inmoonlight/p/6032692.html
Copyright © 2011-2022 走看看