Humble Numbers_usaco3.1.3_堆
来源:互联网 发布:国外包车软件 编辑:程序博客网 时间:2024/04/28 03:01
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:wjp13241PROG:humbleLANG: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;}
- Humble Numbers_usaco3.1.3_堆
- 堆----【USACO3.1.3】Humble Numbers丑数
- OpenJudge_P1249 Humble Numbers(堆)
- USACO3.1.3 Humble Numbers (humble)
- USACO3.1.3 Humble Numbers (humble)
- usaco3.1.3 Humble Numbers
- [数据结构][usaco3.1.3]Humble Numbers
- USACO 3.1 Humble Numbers丑数_优先队列
- 数据结构_堆排序
- 树_最小堆
- 学习笔记_堆
- 计蒜客 _堆积木
- 06_堆排序
- 堆排序-------------->_<
- 【数据结构_堆_1098】堆的判断
- 堆_栈_方法区
- 洛谷 2664_切割木板_堆
- jzoj 3928_射击_堆
- fedora下编译qemu for windows
- 堆排序
- javascript 子节点删除
- html 基本标签
- pthread_mutexattr_setpshared使用man 查询不到安装包下载方法,以及VIM性感插件
- Humble Numbers_usaco3.1.3_堆
- Apache Hadoop 入门教程
- 使用ckfinder上传中文图片乱码解决方法之tomcat配置URIEncoding
- spark中flatmap和map的区别
- Andoid屏幕适配全攻略
- 116. cURL 简介(2)
- Caused by: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.
- HttpClient4.5实现页面静态化
- RDD[Vector]