https://www.luogu.org/problemnew/show/P2723

题解:

C++版本一

题解:STL+优化

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
int ans,cnt,flag,temp,sum;
struct node{int v;int i;bool operator < (const node &S)const{return v>S.v;}
};
ll a[N];
priority_queue<node>heap;
char str;
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d%d",&k,&n);for(ll i=1;i<=k;i++){scanf("%lld",&a[i]);}heap.push({1,1});node humble;t=n;n++;while(n--){humble=heap.top();heap.pop();for(int i=humble.i;i<=k;i++){ll num=humble.v*a[i];if(num<=(1ll<<31)-1)heap.push({num,i});}}printf("%d\n",humble.v);//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif//cout << "Hello world!" << endl;return 0;
}

C++版本二

题解:贪心

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;int i,j,n,m,k;
long long a[150],s[100011],f[100011];int main(){cin>>k>>n;for(i=1;i<=k;i++) cin>>a[i];f[0]=1;for(i=1;i<=n;i++){m=2147483647;for(int j=1;j<=k;j++){while(a[j]*f[s[j]]<=f[i-1]) s[j]++;if(a[j]*f[s[j]]<m) m=a[j]*f[s[j]];}f[i]=m;}cout<<f[n]<<endl;return 0;
}

C++版本三

题解:平衡树

#include <iostream>
#include <cstdio>using namespace std;const int S = 1 << 20;
char frd[S], *hed = frd + S;
const char *tal = hed;inline char nxtChar()
{if (hed == tal)fread(frd, 1, S, stdin), hed = frd;return *hed++;
}inline int get()
{char ch; int res = 0;while (!isdigit(ch = nxtChar()));res = ch ^ 48;while (isdigit(ch = nxtChar()))res = res * 10 + ch - 48;return res;
}typedef long long ll;
const int N = 11e4 + 5;
ll Int = 2147483647ll;
int fa[N], lc[N], rc[N], sze[N], val[N];
int T, n, k, rt, top, stk[N], a[N];inline void Push(int x) {sze[x] = sze[lc[x]] + sze[rc[x]] + 1;}inline void Rotate(int x)
{int y = fa[x], z = fa[y];int b = (lc[y] == x ? rc[x] : lc[x]);fa[y] = x; fa[x] = z;if (b) fa[b] = y;if (z) (lc[z] == y ? lc[z] : rc[z]) = x;if (lc[y] == x) rc[x] = y, lc[y] = b;else lc[x] = y, rc[y] = b;Push(y);
}inline bool Which(int x) {return lc[fa[x]] == x;}inline void Splay(int x, int tar)
{while (fa[x] != tar){if (fa[fa[x]] != tar)Which(fa[x]) == Which(x) ? Rotate(fa[x]) : Rotate(x);Rotate(x); }Push(x);if (!tar) rt = x;
}inline void Insert(int vi)
{int x = rt, y = 0, dir;while (x){y = x;if (val[x] == vi) return ;if (val[x] > vi) x = lc[x], dir = 0;else x = rc[x], dir = 1;  }int w = y; if (y) ++sze[y];while (fa[w]) ++sze[w = fa[w]];x = top ? stk[top--] : ++T;fa[x] = y; val[x] = vi; sze[x] = 1;if (y) (dir ? rc[y] : lc[y]) = x; Splay(x, 0);
}inline void Join(int x, int y)
{int w = y;while (lc[w]) w = lc[w];lc[fa[x] = w] = x; fa[rt = y] = 0;Splay(w, 0);
}inline void Delete(int x)
{Splay(x, 0);stk[++top] = x;int L = lc[x], R = rc[x];lc[x] = rc[x] = 0;if (!L || !R) fa[rt = L + R] = 0;else Join(L, R);
}inline int GetKth(int k)
{int x = rt;while (x){if (k <= sze[lc[x]])x = lc[x];else {k -= sze[lc[x]] + 1;if (!k) return x;x = rc[x];}}return 0;
}inline void Print(int x)
{if (!x) return ;Print(lc[x]); Print(rc[x]); stk[++top] = x; fa[x] = lc[x] = rc[x] = 0;
}inline int FindMin() {int x = rt; while (lc[x]) x = lc[x]; return x;}int main()
{k = get(); n = get(); int x, cnt = 0; ll y;for (int i = 1; i <= k; ++i) Insert(a[i] = get());while (++cnt <= n){y = val[x = FindMin()]; Delete(x);for (int i = 1; i <= k; ++i) if (y * a[i] < Int) Insert(y * a[i]);else break;if (sze[rt] + cnt >= n) {Int = val[x = GetKth(n - cnt)]; Splay(x, 0); Print(rc[x]); rc[x] = 0; Push(x);}}cout << y << endl;
}

丑数 Humble Numbers相关推荐

  1. 比紫书优化,14行代码AC——例题 5-7 丑数(Ugly Numbers,UVa 136)——解题报告

    题意: 丑数是一些因子只有2,3,5的数.数列1,2,3,4,5,6,8,9,10,12,15--写出了从小到大的前11个丑数,1属于丑数.现在请你编写程序,找出第1500个丑数是什么. 没有输入 输 ...

  2. 洛谷P1246C语言,codevs1246 丑数

    题目描述 Description 对于一给定的素数集合 S = {p1, p2, ..., pK}, 来考虑那些质因数全部属于S 的数的集合.这个集合包括,p1, p1p2, p1p1, 和 p1p2 ...

  3. usaco ★Humble Numbers 丑数

    ★Humble Numbers 丑数 对于一给定的素数集合 S = {p1, p2, ..., pK}, 来考虑那些质因数全部属于 S 的数的集合.这个集合包括,p1, p1p2, p1p1, 和 p ...

  4. Humble Numbers(丑数) 超详解!

    给定一个素数集合 S = { p[1],p[2],...,p[k] },大于 1 且素因子都属于 S 的数我们成为丑数(Humble Numbers or Ugly Numbers),记第 n 大的丑 ...

  5. Humble Numbers (谦卑数 || 丑数)

    Humble Numbers 题目来源:https://vjudge.net/contest/278033#problem/B || http://acm.hdu.edu.cn/showproblem ...

  6. poj 2247 Humble Numbers

    Humble Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9453   Accepted: 4440 题目 ...

  7. 《剑指offer》-- 把数组排成最小的数、丑数、二进制中1的个数、表示数值的字符串、替换空格

    一.把数组排成最小的数: 1.题目: 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为 ...

  8. HDU1492 The number of divisors(约数) about Humble Numbers【约数】

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

  9. 【OJ】1089: 丑数

    详尽代码和说明如下: #include<stdio.h> long long min(long long&a, long long &b,long long &c, ...

最新文章

  1. 6月11号=》121页-125页
  2. python代码大全o-Python实现的一个自动售饮料程序代码分享
  3. 【Android 组件化】路由组件 ( 使用 JavaPoet 生成路由表类 )
  4. 工作以后如何有效学习
  5. 淘宝网的技术发展史(一)——个人网站时代
  6. 牛客网数据开发题库_数据库刷题—牛客网(21-30)
  7. 人人都能看懂的 6 种限流实现方案!
  8. 摩托罗拉mpkg安装签名方法研究
  9. PostgreSQL 源码解读(152)- PG Tools#4(ReceiveXlogStream)
  10. 数据库(MYSQL)之元数据
  11. 在电脑上安装android,在电脑上安装Android模拟器
  12. 自动生成带昵称的头像(仿照钉钉头像)
  13. 【前端】报错TypeError: Cannot create property ‘xxx‘ on string ‘xxx‘
  14. tplink里的DMZ主机是什么意思
  15. 枚举 _枚举的其他应用
  16. 英文论文写作摘要的时态和语态
  17. 数字经济专家高泽龙:映客更名映宇宙,元宇宙会成为映客下一个增长引擎吗?
  18. 安超云生态|安超云与长城超云完成兼容互认证 携手打造协同生态
  19. 孙宇晨受邀参加36氪元宇宙峰会并发表主题演讲
  20. linux 中了挖矿病毒

热门文章

  1. java byte char io流_吃透Java IO:字节流、字符流、缓冲流
  2. ipone android 省流量,总担心 iPhone 偷跑流量如何解决?iPhone 如何设置可以节省流量?...
  3. 淮阳一高2021高考成绩查询,周口教育网2021年淮阳中招成绩查询系统
  4. java程序员需要考证_泄题了!Java程序员最可能被考到的14个面试题
  5. 三十一、Python读写docx文件
  6. AAAI 2021 | 上海交大提出基于有监督解耦的信息瓶颈算法
  7. BERT原理、代码、相关模型、精调技巧,看这个就够了
  8. 福利满满 | 天元MegEngine贡献者计划全面启动!
  9. 中国学霸们被世界名校集体退学,原因竟然是……
  10. 第三期CSIG图像图形学科前沿讲习班-详细日程