CF 483B Friends and Presents(二分)

这里v是所选1到v这个序列的最大值,然后要求最小值,就要想到最大值最小化,就要用二分搜素

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
int main()
{
    ll cnt1,cnt2,x,y,xb,yb,xyb,low,up,mid,ans=inf;
    scanf("%lld %lld %lld %lld",&cnt1,&cnt2,&x,&y);
    low=0;
    up=1e15;
    while(low<=up)
    {

        mid=(low+up)>>1;
        //cout<<"******************************88"<<endl;
        //cout<<"mid:"<<mid<<"  low:"<<low<<"  up:"<<up<<endl;
        //cout<<"******************************88"<<endl;
        xb=mid/x;
        yb=mid/y;
        xyb=mid/(x*y);
        if((mid-xyb>=cnt1+cnt2)&&(mid-xb>=cnt1)&&(mid-yb>=cnt2))
        {
            ans=mid;
            up=mid-1;
        }
        else
            low=mid+1;
    }

    printf("%lld\n",ans);

    return 0;


}

 

posted @ 2018-08-06 20:00  eason99  阅读(86)  评论(0编辑  收藏  举报