题目 : 链接:https://ac.nowcoder.com/acm/problem/235254
谁能告诉我为什么16行要这样写,而不是用temp-=ceil((double)arr[i]/k);????
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k;
const int maxn=1e5+5;
int arr[maxn];
int ans;
bool check(int mid)
{
int temp=mid;
for(int i=1;i<=n;i++)
{
if(arr[i]<=mid)continue;
else
{
temp-=ceil((double)(arr[i]-mid)/(k-1));
}
}
return temp>=0;
}
signed main()
{
ios::sync_with_stdio(false),cin.tie(0);
cin>>n;
int big=0;
for(int i=1;i<=n;i++)
{
cin>>arr[i];
big=max(big,arr[i]);
}
cin>>k;
int l=0,r=big;
while(l<=r)
{
int mid=(l+r)>>1;
if(check(mid))
{
ans=mid;
r=mid-1;
}
else
{
l=mid+1;
}
}
cout<<ans;
return 0;
}
标签:二分,arr,晾衣服,int,big,mid,cin,ans
From: https://www.cnblogs.com/benscode/p/18625063