zoj 3278【二分】

來源:互聯網
上載者:User

 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3278

一道不錯的二分。。。第一次寫這樣的二分

#include<iostream>#include<vector>#include<map>#include<stack>#include<algorithm>#include<queue>#include<list>#include<set>#include<string.h>#include<stdlib.h>#include<math.h>#include<stdio.h>#include<ctype.h>#include<iomanip>using namespace std;#define LL long long#define pi acos(-1)#define N 100010#define INF 999999999#define eps 1e-8//****************************************//zoj 3278//Copyright@leolin All rights reserved.//****************************************int b[N],g[N];bool cmp(int a,int b){    return a>b;}int main(){    //freopen("a.txt","r",stdin);    int n,m;    LL k;    while(cin>>n>>m>>k)    {        int i;        for(i=1;i<=n;i++)        scanf("%d",&b[i]);        for(i=1;i<=m;i++)        scanf("%d",&g[i]);        sort(b+1,b+n+1,cmp);        sort(g+1,g+m+1,cmp);        LL l1=1ll*b[n]*g[m],r1=1ll*b[1]*g[1],mid1;        LL ans=l1;        while(l1<=r1)        {            mid1=(l1+r1)/2;            LL sum=0;            for(i=1;i<=n;i++)//mei ju boy            {                int l2=1,r2=m,mid2;                LL t=0;                while(l2<=r2)                {                    mid2=(l2+r2)/2;                    if(1ll*b[i]*g[mid2]>=mid1)                    {                        t=mid2;                        l2=mid2+1;                    }                    else                        r2=mid2-1;                }                sum+=t;//大於mid1的個數            }            if(sum>=k)            {                ans=mid1;                l1=mid1+1;            }            else            r1=mid1-1;        }        cout<<ans<<endl;    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.