Humble Numbers

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.

SAMPLE INPUT (file humble.in)

4 19
2 3 5 7

OUTPUT FORMAT

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

SAMPLE OUTPUT (file humble.out)

27

————————————————————

所以就是一道set的简单应用

然而我的内存在最后一个测试点炸了

事实上操作内存不需要n*k然后第n次的begin,只要不断维护这个序列是n长最后把--end抛出去

然后就没有内存问题了,还会比较快

 /*
ID: ivorysi
PROG: humble
LANG: C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <set>
#define siji(i,x,y) for(int i=(x);i<=(y);++i)
#define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
#define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
#define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
#define inf 0x7fffffff
#define MAXN 100005
#define ivorysi
using namespace std;
typedef long long ll;
set<int> s;
int n,k,pri[];
void solve() {
scanf("%d%d",&k,&n);
siji(i,,k) {scanf("%d",&pri[i]);s.insert(pri[i]);}
siji(i,,k){
set<int>::iterator k=s.begin();
while() {
int tm=(*k)*pri[i];
if(tm<) break;
if(s.size()>n) {
s.erase(--s.end());
if(tm>(*--s.end()))
break;
}
s.insert(tm);
++k;
}
}
printf("%d\n",*(--s.end()));
}
int main(int argc, char const *argv[])
{
#ifdef ivorysi
freopen("humble.in","r",stdin);
freopen("humble.out","w",stdout);
#else
freopen("f1.in","r",stdin);
#endif
solve();
}

USACO 3.1 Humble Numbers的更多相关文章

  1. USACO Humble Numbers

    USACO  Humble Numbers 这题主要是两种做法,第一种是比较常(jian)规(dan)的-------------用pq(priority_queue)维护,每次取堆中最小值(小根堆) ...

  2. 洛谷P2723 丑数 Humble Numbers

    P2723 丑数 Humble Numbers 52通过 138提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 题目背景 对于一给定的素数 ...

  3. Luogu2723丑数Humble Numbers【归并排序】

    Luogu2723丑数Humble Numbers 题目背景 对于一给定的素数集合 S = {p1, p2, ..., pK},考虑一个正整数集合,该集合中任一元素的质因数全部属于S.这个正整数集合包 ...

  4. 洛谷P2723 丑数 Humble Numbers [2017年 6月计划 数论07]

    P2723 丑数 Humble Numbers 题目背景 对于一给定的素数集合 S = {p1, p2, ..., pK},考虑一个正整数集合,该集合中任一元素的质因数全部属于S.这个正整数集合包括, ...

  5. [poj2247] Humble Numbers (DP水题)

    DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...

  6. HDU - The number of divisors(约数) about Humble Numbers

    Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence ...

  7. A - Humble Numbers

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Pract ...

  8. The number of divisors(约数) about Humble Numbers[HDU1492]

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  9. Humble Numbers

    Humble Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9988 Accepted: 4665 Descri ...

随机推荐

  1. IOS开发小功能1:引导页的开发

    效果图如上,实现的是一个页面引导页,最后跳到主页面,主页面是一个navigationController,但是导航栏给我隐藏了. 文件目录:自己定制的viewcontroller以及navigatio ...

  2. C++构造 下一个排列 的函数

    今天围观刘汝佳神犇的白书发现了一个好用的函数: next_permutation(); 可以用于可重, 或者不可重集, 寻找下一个排列. 时间复杂度尚不明. //适用于不可重和可重集的排列. # in ...

  3. WCF从零学习之设计和实现服务协定2

    WCF从零学习之设计和实现服务协定(二)   在创建服务协定之前,有很多WCF术语,比如: 消息.服务.终结点 创建协定 类或接口都可以定义服务协定,建议使用接口,因为接口可以直接对服务协定建模 服务 ...

  4. 迟到的 WPF 学习 —— 依赖项属性

    本章学习依赖项属性,英文原文 Dependency Property,它是传统 .Net Framework 属性的扩展,是 WPF 的专属,但所幸使用起来和传统属性几乎一样.WPF 元素所提供的大多 ...

  5. IIS日志分析的作用

    站长都知道有ISS日志,可是有很少人去关注它,也许你觉得在一些站长工具里面我们就能找到我们想要的工具,哪你就错了,我们的网站被收入靠的是蜘蛛,想要真正了解蜘蛛,就一定要好好重视iss日志分析,为什么这 ...

  6. 前端开发的使用服务器环境开源项目 D2Server 可替代Apache

    推荐一个前端开发的使用服务器环境开源项目 D2Server 可替代Apache   攻欲善其事,必先利其器.前端开发,编辑器我们有了Sublime Text2,配置Server环境用……你可能会选择A ...

  7. 谱聚类(Spectral Clustering)详解

    谱聚类(Spectral Clustering)详解 谱聚类(Spectral Clustering, SC)是一种基于图论的聚类方法——将带权无向图划分为两个或两个以上的最优子图,使子图内部尽量相似 ...

  8. sqlserver生成随机数 2011-12-21 15:47 QQ空间

    -创建视图 create view myview as select re=rand() --自定义函数:取得指定范围的随机数 create function mydata( @a int, @b i ...

  9. [Oracle] CPU/PSU补丁安装教程

    什么是CPU/PSU Oracle CPU的全称是Critical Patch Update, Oracle对于其产品每个季度发行一次安全补丁包,通常是为了修复产品中的安全隐患. Oracle PSU ...

  10. 在 Cordova/Phonegap for Android 中包含中文文件名的页面

    在 Cordova/Phonegap for Android 中包含中文文件名的页面 本贴首发于: http://xuekaiyuan.com/forum.php?mod=viewthread& ...