【转】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 p1, p2, p3, i;
        while(cin>>p1>>p2>>p3>>i)
        {
                int k1, k2, k3;
                k1=k2=k3=0;
                num[0]=1;
                for(int j=1; j<i+1; j++)
                {
                        long long x1=num[k1]*p1;
                        long long x2=num[k2]*p2;
                        long long x3=num[k3]*p3;
                        long long Min=min(x1, x2);
                        Min=min(Min, x3);
                        num[j]=Min;
                        if(Min==x1) k1++;
                        if(Min==x2) k2++;
                        if(Min==x3) k3++;
//                        cout<<"_______________________"<<endl<<endl;
//                        cout<<"x1="<<x1<<endl;
//                        cout<<"x2="<<x2<<endl;
//                        cout<<"x3="<<x3<<endl;
//                        cout<<"Min="<<Min<<endl;
//                        cout<<"k1 k2 k3="<<k1<<" "<<k2<<" "<<k3<<endl;
//                        cout<<"_______________________"<<endl<<endl;
                }
                cout<<num[i]<<endl;
        }
}

  

时间: 2024-07-31 12:41:58

【转】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, ... 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

hdu 5104 Primes Problem (素数 打表 水)

http://acm.hdu.edu.cn/showproblem.php?pid=5104 #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> using namespace std; int isp[10000+100]; int prime[10000]; int coun; bool isprime(int x)

hdu 5351 MZL&#39;s Border 打表+高精度

MZL's Border Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 462    Accepted Submission(s): 127 Problem Description As is known to all, MZL is an extraordinarily lovely girl. One day, MZL was pl

[HDOJ6154] CaoHaha&#39;s staff(规律, 打表, 二分)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 有些题一辈子只会做一次,比如这个题.. 题意:炒鸡难懂,学弟读明白的.懒得描述,反正这题以后不会再做. f(i)表示i个线段能围成的最大面积,画画图就会发现一个规律. 然后查询的时候二分最小的大于等于s的即可. 1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ 5 ┓┏┓┏┓┃ / 6 ┛┗┛┗┛┃ノ) 7 ┓┏┓┏┓┃ 8 ┛┗┛

hdu acm 1425 sort(哈希表思想)

sort Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25803    Accepted Submission(s): 7764 Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且

HDU 4952 Number Transformation 规律题

打表可以知道到后面增量都一样了,, 推论就是  i 和 i+1 互质 #include <cstdio> #include <algorithm> #include <cstring> #include <iostream> using namespace std; typedef long long ll; const ll mx = 120000; int main() { int cas = 0; ll x, k, y, dis, i; while (

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