• CF912E Prime Gift(Meeting In The Middle+Two pointers)


    原题

    挂个链接CodeForces

    题目大意:给定k个质数,求出约数中只有由这几个数组合一下(可以多次用一个数)的第k个值

    Solution

    分析:

    我们看到n是16,然后如果爆搜n/2是可以过的.所以考虑Meeting In The Middle

    他让我们求第k个数,理所应当地想到二分答案.

    然后我们先把所有的组合求出来,然后二分答案判断就好了.

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<math.h>
    #include<iostream>
    #include<queue>
    #include<algorithm>
    #define ll long long
    #define re register
    using namespace std;
    inline int gi(){
      int sum=0,f=1;char ch=getchar();
      while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
      while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
      return f*sum;
    }
    inline ll gl(){
      ll sum=0,f=1;char ch=getchar();
      while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
      while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
      return f*sum;
    }
    int n,p[20],t1,t2;
    ll s1[5000010],s2[5000010],k;
    void dfs1(int x,ll s){
      if(x>n){s1[++t1]=s;return;}
      for(ll w=1;;w*=p[x]){dfs1(x+2,s*w);if(1e18/p[x]<w*s)break;}
    }
    void dfs2(int x,ll s){
      if(x>n){s2[++t2]=s;return;}
      for(ll w=1;;w*=p[x]){dfs2(x+2,s*w);if(1e18/p[x]<w*s)break;}
    }
    int main(){
      n=gi();
      for(re int i=1;i<=n;i++)p[i]=gi();
      sort(p+1,p+n+1);
      dfs1(1,1);dfs2(2,1);
      sort(s1+1,s1+t1+1);sort(s2+1,s2+t2+1);
      k=gi();
      ll l=0,r=1e18,ans;
      while(l<=r){
        ll mid=(l+r)>>1,tot=0;
        for(re int i=1,p=t2;i<=t1;i++,tot+=p)
          while(p && mid/s1[i]<s2[p])p--;
        if(tot<k)l=mid+1;
        else{ans=mid;r=mid-1;}
      }
      printf("%lld
    ",ans);
      return 0;
    }
    
  • 相关阅读:
    Boolean()类型转换
    ECMAscript 变量作用域
    jQuery 添加样式属性的优先级别
    css类选择器类名覆盖优先级
    巡风扫描器安装-windows部署
    atom无法安装插件的解决方法之一
    网络爬虫url跳转代码
    查看天气的代码
    三级地名菜单
    购物清单代码
  • 原文地址:https://www.cnblogs.com/cjgjh/p/9769489.html
Copyright © 2020-2023  润新知