Codeforces Round #456 (Div. 2) 912E E. Prime Gift
题
OvO http://codeforces.com/contest/912/problem/E
解
首先把这个数字拆成个子集,各自生成所有大小1e18及以下的积
对于最坏情况,即如下数据
16
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53
把她肢解成
2 3 5 7 11 13 和 17 19 23 29 31 37 41 43 47 53 两个集合
这两个集合生成的1e18及以下的积的数量分别为 958460个 和 505756个,并不大,而且两个集合中的积必定是两两不相等的(除了)。
记两个集合大小的和为 |S|
两个集合生成的积各自排一下序
然后二分答案,对于每个答案 u,可以 O(|S|) 得到他是第几大。
具体做法是枚举从到小枚举第一个集合的积 t1,然后计算一下第二个集合的积中有多少积和 t1 相乘小于等于 u,
由于是从大到小枚举的,所以 t1 必然递增,所以第二个集合的积中符合条件的积的数量也必然是递增的,所以只要扫一遍就行。
然后要注意的是直接用 long long 来进行计算比较好,double的精度貌似不太够
(参考自这里->http://codeforces.com/contest/912/submission/33938779)
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <vector> using namespace std; typedef long long ll; const ll INF=1e18;
const int N=24; vector<ll> seg[2];
int p[N],n;
ll ansid; void dfs(int li,int ri,ll val,int id)
{
seg[id].push_back(val);
for(int i=li;i<=ri;i++)
if(INF/p[i]>=val)
dfs(i,ri,val*p[i],id);
} ll cnt(ll num)
{
int j=0;
ll ret=0;
for(int i=seg[0].size()-1;i>=0;i--)
{
while(j<seg[1].size() && seg[1][j]<=num/seg[0][i])
j++;
ret+=j;
}
return ret;
} void solve()
{
int i,j;
dfs(1,min(6,n),1,0);
dfs(min(6,n)+1,n,1,1);
sort(seg[0].begin(),seg[0].end());
sort(seg[1].begin(),seg[1].end());
// cout<<seg[0].size()<<' '<<seg[1].size()<<endl;
ll li=0,ri=INF,mid;
while(li<ri-1)
{
mid=(li+ri)>>1;
if(cnt(mid)>=ansid)
ri=mid;
else li=mid;
}
printf("%I64d\n",ri);
} int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&p[i]);
scanf("%I64d",&ansid);
solve();
return 0;
} /* 16
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53
2 */
Codeforces Round #456 (Div. 2) 912E E. Prime Gift的更多相关文章
- Codeforces Round #456 (Div. 2)
Codeforces Round #456 (Div. 2) A. Tricky Alchemy 题目描述:要制作三种球:黄.绿.蓝,一个黄球需要两个黄色水晶,一个绿球需要一个黄色水晶和一个蓝色水晶, ...
- Codeforces Round #456 (Div. 2) B. New Year's Eve
传送门:http://codeforces.com/contest/912/problem/B B. New Year's Eve time limit per test1 second memory ...
- Codeforces Round #456 (Div. 2) A. Tricky Alchemy
传送门:http://codeforces.com/contest/912/problem/A A. Tricky Alchemy time limit per test1 second memory ...
- Codeforces Round #456 (Div. 2) 912D D. Fishes
题: OvO http://codeforces.com/contest/912/problem/D 解: 枚举每一条鱼,每放一条鱼,必然放到最优的位置,而最优位置即使钓上的概率最大的位置,即最多的r ...
- Codeforces Round #456 (Div. 2) B. New Year's Eve
B. New Year's Eve time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 【Codeforces Round #456 (Div. 2) A】Tricky Alchemy
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 统计需要的个数. 不够了,就买. [代码] #include <bits/stdc++.h> #define ll lo ...
- 【Codeforces Round #456 (Div. 2) B】New Year's Eve
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然10000..取到之后 再取一个01111..就能异或成最大的数字了. [代码] /* 1.Shoud it use long ...
- 【Codeforces Round #456 (Div. 2) C】Perun, Ult!
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] set1 < pair < int,int > > set1;记录关键点->某个人怪物永远打不死了,第 ...
- Codeforces Round #456 (Div. 2) B题
B. New Year's Evetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputout ...
随机推荐
- 在springMVC框架中集成quartz作业调度器
1.首先需要导入这几个jar包,如下图: 其中log4j,quartz,slf4j-api,slf4j-log4j12我是在项目中都引用了 2.引用完jar包后,新建一个作业调度类,执行作业调度逻辑, ...
- JAVA开发者大会:拍拍贷MQ系统原理与应用
--喜欢记得关注我哟[shoshana]-- 前记: 5月12号参加了JAVA开发者大会,就<拍拍贷消息系统原理及应用> 作者:李乘胜老师 关于PMQ的分享整理一下笔记以及笔记的思考 和复 ...
- 数据分析—win7+ipython+notebook安装
先安装python 3.x 然后 cmd 执行 pip3 ipython 然后 cmd 执行 pip3 install jupyter notebook 然后 cmd 执行 jupyter noteb ...
- global和nonlocal的区别
global可以在任何地方修饰变量,而且被global修饰的变量直接被标识为全局变量,对该变量修改会影响全局变量的值,但不影响函数中未被global修饰的同名变量(依然是局部变量),nonlocal只 ...
- 【Trie】The XOR Largest Pair
[题目链接] https://loj.ac/problem/10050 [题意] 给出n个数,其中取出两个数来,让其异或值最大. [题解] 经典的01字典树问题. 首先需要把01字典树建出来. 然后对 ...
- Fiddler 抓包工具详解
Fiddler是一个蛮好用的抓包工具,可以将网络传输发送与接受的数据包进行截获.重发.编辑.转存等操作.也可以用来检测网络安全.反正好处多多,举之不尽呀!当年学习的时候也蛮费劲,一些蛮实用隐藏的小功能 ...
- Oracle练习(一)
Oracle 1.检索部门编号.部门名称.部门所在地及其每个部门的员工总数. select d.deptno,d.dname,d.loc,count(*) from emp e,dept d wher ...
- 超详细,新手都能看懂 !使用SpringBoot+Dubbo 搭建一个简单的分布式服务
来自:JavaGuide Github 地址:https://github.com/Snailclimb/springboot-integration-examples 目录: 使用 SpringBo ...
- Java并发与多线程教程(3)
Java中的锁 锁像synchronized同步块一样,是一种线程同步机制,但比Java中的synchronized同步块更复杂.因为锁(以及其它更高级的线程同步机制)是由synchronized同步 ...
- vue阻止右键默认行为
vue阻止右键默认行为 <!--不阻止右键菜单(浏览器行为),右键执行函数show--> <input type="button" value="按钮& ...