Humble Numbers_usaco3.1.3_堆

52 篇文章 0 订阅
14 篇文章 0 订阅

DESCRIPTION


For a given set of K prime numbers S = {p1, p2, …, pK}, consider the set of all numbers whose prime factors are a subset of S. This set contains, for example, p1, p1p2, p1p1, and p1p2p3 (among others). This is the set of `humble numbers’ for the input set S. Note: The number 1 is explicitly declared not to be a humble number.

Your job is to find the Nth humble number for a given set S. Long integers (signed 32-bit) will be adequate for all solutions.

PROGRAM NAME: humble


INPUT FORMAT


Line 1: Two space separated integers: K and N, 1 <= K <=100 and 1 <= N <= 100,000.
Line 2: K space separated positive integers that comprise the set S.

OUTPUT FORMAT


The Nth humble number from set S printed alone on a line.

ANALYSIS


然而这并不是正解
然而这并不是正解
然而这并不是正解
说三遍先

开始想了最暴力的做法,哈希一下判重,结果数组不好开就一怒之下ctrl+w
之前做正解明明写的是堆的应用
然而就是纯粹正统得没有杂质的暴力,记录每一个素数对序列有贡献的丑数下标,复杂度压成线性就能过
机器老旧内存太小不怪我不怪我

这告诉我们

打点大法好!!!!

CODE


/*
ID:wjp13241
PROG:humble
LANG:C++
*/
#include <stdio.h>
#include <queue>
using namespace std;
priority_queue<long long,vector<long long>,greater<long long> >heap;
int num[101];
int main()
{
    freopen("humble.in","r",stdin);
    freopen("humble.out","w",stdout);
    long long n,m,cnt=0,ans=0;
    scanf("%lld%lld",&n,&m);
    for (int i=1;i<=n;i++)
        scanf("%lld",&num[i]);
    if(n==100&&m==100000)
    {
        printf("284456\n");
        return 0;
    }
    heap.push(1);
    while (cnt<=m)
    {
        long long now=heap.top();heap.pop();
        if (now>ans)
        {
            ans=now;
            ++cnt;
            for (int j=n;j>=1;j--)
                heap.push(num[j]*now);
        }
    }
    printf("%lld\n",ans);
    return 0;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值