VJ-11 个人赛
作者:互联网
bookshelf filling
二分,从右边的长度为b的书中选tt本,看上面剩下的空间能否摆下tt本。因为tt的值越小,越有可能摆下,所以满足二分的性质。
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e5+10; int a,b,h; ll n,m; bool judge(ll tt) { ll cnt1=(n/b)*(h-a); ll cnt2=(((n%b+m-tt)/b)*(h-b)); if (cnt1+cnt2>=tt)return true; return false; } signed main() { int t; scanf("%d",&t); while (t--) { scanf("%d%d%lld%lld%d",&a,&b,&n,&m,&h); ll l=0,r=m-1; while (l<r) { ll mid=(l+r+1)>>1; if (judge(mid))l=mid; else r=mid-1; } printf("%lld\n",n+m-l); } return 0; }
标签:11,return,int,VJ,mid,tt,个人赛,judge,ll 来源: https://www.cnblogs.com/Mercury1988/p/16364607.html