hdu 3199 Hamming Problem(构造?枚举?)

题意:

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.

给p1,p2,p3,n,求Hn(p1,p2,p3)

思路:

和humble numbers那题一样,,,看代码,,

代码:

int p1,p2,p3,x;
ll a[1000005];

int main(){

    while(scanf("%d%d%d%d",&p1,&p2,&p3,&x)!=EOF){
        if(p1>p2) swap(p1,p2);
        if(p1>p3) swap(p1,p3);
        if(p2>p3) swap(p2,p3);
        a[1]=1;
        int cn=1;
        while(cn<=x){
            ll temp;
            ll ans=INF;
            rep2(i,cn,1){
                temp=a[i]*p1;   if(temp>a[cn]) ans=min(ans,temp);
                temp=a[i]*p2;   if(temp>a[cn]) ans=min(ans,temp);
                temp=a[i]*p3;   if(temp>a[cn]) ans=min(ans,temp);
                if(temp<=a[cn]) break;
            }
            a[++cn]=ans;
        }
        printf("%I64d\n",a[cn]);
    }

    return 0;
}
时间: 2024-10-13 23:23:53

hdu 3199 Hamming Problem(构造?枚举?)的相关文章

【转】HDU 3199 Hamming Problem: 规律打表

应该不是数论···逻辑思维?找规律?暂且放到支个分类下··· 我的理解: 数组 num表 保存 只有P1 P2 or P3的因子的 常数 并按递增顺序. 通过已有的常数 每次循环相应的乘以P1 P2 P3, 就保证了表中的 常数 的因子排他性. 也可以 手推+程序显示 探究其规律. #include<iostream> using namespace std; const int Size=100000; long long num[Size]; int main() { long long

HDU 5371 Hotaru&#39;s problem(manacher + 枚举啊)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5371 Problem Description Hotaru Ichijou recently is addicated to math problems. Now she is playing with N-sequence. Let's define N-sequence, which is composed with three parts and satisfied with the foll

hdu 4430 Yukari&#39;s Birthday 枚举+二分

注意会超long long 开i次根号方法,te=(ll)pow(n,1.0/i); Yukari's Birthday Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3262    Accepted Submission(s): 695 Problem Description Today is Yukari's n-th birt

HDU3199 Hamming Problem 【数论】

Hamming Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 703    Accepted Submission(s): 289 Problem Description For each three prime numbers p1, p2 and p3, let's define Hamming sequence

HDU 3549 Flow Problem ( 最大流 -EK 算法)

C++,G++的读取速度差距也太大了 Flow Problem 题意:n,m表示n个点m条有向带权边 问:从1-n最大流多少 裸最大流,拿来练手,挺不错的 #include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <queue> #include <algorithm> const int N = 210; #define

HDU 3549 Flow Problem 网络最大流问题 Edmonds_Karp算法

题目链接:HDU 3549 Flow Problem Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 8218    Accepted Submission(s): 3824 Problem Description Network flow is a well-known difficult problem f

HDU Hotaru&#39;s problem(Manacher算法+贪心)

manacher算法详见 http://blog.csdn.net/u014664226/article/details/47428293 题意:给一个序列,让求其最大子序列,这个子序列由三段组成,第一段和第二段对称,第一段和第三段一样. 思路:首先利用Manacher算法求出以任意两个相邻元素为中心的回文串长度,用a[i]表示i-1,i为中心的回文串长度的一半, 那么问题就转化成了求最大的x,使得a[i]>=x,a[i+x]>=x,这一步可以贪心来做. 将a[i]从大到小排序(间接排序保留

HDU 4961 Boring Sum 构造题

用一个数组c, c[i]表示i这个数出现的最近数字是几. 那么当加入一个6,则 c[1] = c[2] = c[3] = c[6] = 6; ==最近怎么都要开挂啊.. #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; const int N = 100005; inl

网络流 HDU 3549 Flow Problem

网络流 HDU 3549 Flow Problem 题目:http://acm.hdu.edu.cn/showproblem.php?pid=3549 用增广路算法进行求解,注意的问题有两个: 1. 每次增广的时候,反向流量也要进行更行,一开始没注意,WA了几次 ORZ 2. 对于输入的数据,容量要进行累加更新. // 邻接矩阵存储 #include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; const i