$CF912E\ Prime\ Gift$ 二分+搜索
正解:二分+搜索
解题报告:
因为翻译真的很$umm$所以还是写下题目大意$QwQ$,就说给定一个大小为$n$的素数集合,求出分解后只含这些质数因子的第$K$小整数
考虑先把质数分两堆,$meet-in-the-middle$搜出每堆能表示的数.
然后二分答案,扫左边的数看右边有多少个数满足相乘小于等于这个$mid$的,将数量全加起来和$K$比较就成.然后这个查看右边的操作,可以直接一个指针扫下,就不用二分做了$QwQ$.
出于一些不知道原因的玄学原因,在$meet-in-the-middle$的时候最好是两个两个跳着搜,,,直接简单粗暴对半搜会$T$我也不知道啥原理$kk$.
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define gc getchar()
#define ll long long
#define t(i) edge[i].to
#define ri register int
#define rc register char
#define rb register bool
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)
#define e(i,x) for(ri i=head[x];i;i=edge[i].nxt) const int N=+;
const ll mx=1e18;
int n,p[N];
ll K;
vector<ll>V[]; il int read()
{
rc ch=gc;ri x=;rb y=;
while(ch!='-' && (ch>'' || ch<''))ch=gc;
if(ch=='-')ch=gc,y=;
while(ch>='' && ch<='')x=(x<<)+(x<<)+(ch^''),ch=gc;
return y?x:-x;
}
void dfs(ll dat,ri nw,ri num)
{
if(nw>n){V[num].push_back(dat);return;}
dfs(dat,nw+,num);while(dat<=mx/p[nw])dfs(dat*p[nw],nw+,num),dat=1ll*dat*p[nw];
}
il bool check(ll dat)
{
ri sz=V[].size(),nw=V[].size()-,ret=;
rp(i,,sz-){if(V[][i]>dat || !(~nw))break;while(~nw && V[][nw]>dat/V[][i])--nw;ret+=nw+;}
return ret>=K;
} int main()
{
freopen("912e.in","r",stdin);freopen("912e.out","w",stdout);
n=read();rp(i,,n)p[i]=read();K=read();dfs(,,);dfs(,,);
sort(V[].begin(),V[].end());sort(V[].begin(),V[].end());
ll l=,r=mx;while(l<r){ll mid=(l+r)>>;if(check(mid))r=mid;else l=mid+;}
printf("%lld\n",l);
return ;
}
随机推荐
- deepin 15.11 升级docker-ce 18.01到19.03.1,升级docker compose 1.23到1.24.1
1.升级docker compose ,docker官方安装方法 $ sudo curl -L "https://github.com/docker/compose/releases/dow ...
- jmeter循环取消今天所有的订单
结构 1.首先,添加JDBC Connection Configuration 2.其次添加JDBC request 添加循环控制器 循环控制器下方添加计数器 ${__V(reservationID_ ...
- SQLServer一条SQL查出当月的每一天
from master..spt_values ),,),'2013-02-03')+'-01' as datetime)) 结果: 返回带有年月日的日期 ),),) AS datetime) fro ...
- Python基础:常用函数
1:enumerate enumerate(sequence, start=0) 该函数返回一个enumerate对象(一个迭代器).其中的sequence参数可以是序列.迭代器或者支持迭代的其他对象 ...
- vue element 给指数的div加loading
const loading = this.$loading({ lock: true, text: 'Loading', spinner: 'el-icon-lo ...
- thinkphp 本地配置手机移动端,在pc端访问手机端
- linux常用命令速记
一.命令提示符说明 1. [root@localhost ~]# root: 当前登录用户 localhost: 主机名 ~: 当前所在目录 #: 超级用户提示符($: 普通用户) 2. -rwxr- ...
- Css布局常用 1.盒子内容局中 2. 物理一像素 3.倒三角形 绘制
布局 对象属性 new Person('') 原型链 (创建对象.使用对象中的属性,如果没有那么就去原型找) new Person() Person{ name:'', getname( ...
- ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(16)之轻博客
源码下载地址:http://www.yealuo.com/Sccnn/Detail?KeyValue=c891ffae-7441-4afb-9a75-c5fe000e3d1c 项目到上面一步其实已经算 ...
- vue-learning:33 - component - 内置组件 - 过渡组件transition
vue内置过渡组件transition 目录 什么是过渡 基本过渡或动画实现的语法 css过渡动画:transition / animation js过渡:特定事件钩子函数 各种情形下的过渡实现,使用 ...