nowcoder_Bookshelf Filling_二分

nowcoder_Bookshelf Filling_二分

//
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
LL a,b,n,m,h;

bool judge( LL tt )
{
    LL cnt1=( n/b )*( h-a );
    LL cnt2=( ( n%b+m-tt )/b )*( h-b );    // /b
                    // 还能往上放
    if( cnt1+cnt2 >= tt ) return true;
    else return false;
}

int main()
{
    int t,x,y,mid;

    cin>>t;
    while( t-- )
    {
        cin>>a>>b>>n>>m>>h;
        x=0; y=m;
        while( x<y )
        {
            mid=( x+y )>>1;
            if( judge( mid ) )  x=mid+1;
            else                y=mid;
        }
        cout<<n+m-x+1<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_63173957/article/details/124808547