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;
    }

  • 相关阅读:
    flush table with read lock的轻量级解决方案
    Linux进程关系(转载)
    常用的linux系统监控命令
    MySQL 5.7 InnoDB缓冲池NUMA功能支持——但是别高兴的太早
    网站收集ing....
    【转】程序设计语言中的 一等公民,二等公民,三等公民
    sbt修改为阿里云镜像
    java 中的原始类型与原始封装类型
    【转】MySql中row_number()、rank()、dense_rank() 的区别
    WPS_word使用
  • 原文地址:https://www.cnblogs.com/inmoonlight/p/6032692.html
Copyright © 2011-2022 走看看