正解:二分+搜索

解题报告:

传送门$QwQ$

因为翻译真的很$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 ;
}

随机推荐

  1. Hbase数据模型物理视图

  2. Libev源码分析08:Libev中的信号监视器

    Libev中的信号监视器,用于监控信号的发生,因信号是异步的,所以Libev的处理方式是尽量的将异步信号同步化.异步信号的同步化方法主要有:signalfd.eventfd.pipe.sigwaiti ...

  3. @loj - 3022@ 「CQOI2017」老 C 的方块

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 老 C 是个程序员. 作为一个懒惰的程序员,老 C 经常在电脑上 ...

  4. ODT 珂朵莉树 入门

    #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> ...

  5. centos下iptables使用

    iptables的使用规则: 1.表    (table) 包含4个表(哪个表是当前表取决于内核配置选项和当前模块):4个表的优先级由高到低:raw-->mangle-->nat--> ...

  6. jq获取单选框、复选框、下拉菜单的值

    1.<input type="radio" name="testradio" value="jquery获取radio的值" /> ...

  7. c++第一次的个人作业

    循环结构是c++中重要的结构用以实现代码的反复使用 三种不同的循环结构以及嵌套是必须认识与能够使用的 三种循环结构分别是: 在for循环中可以在for后的括号内加入初始条件,循环条件与参数变化.使得整 ...

  8. Python数据可视化matplotlib和seaborn

    Python在数据科学中的地位,不仅仅是因为numpy, scipy, pandas, scikit-learn这些高效易用.接口统一的科学计算包,其强大的数据可视化工具也是重要组成部分.在Pytho ...

  9. H3C ACL包过滤显示与调试

  10. Vue之webpack的entry和output

    一.文件结构 二.index.html <!DOCTYPE html> <html lang="en"> <head> <meta cha ...