1 条题解
-
0
思路
按厘米建整数单调判定,取可行最大值,避免浮点向上舍入。
参考程序(C++11)
#include <bits/stdc++.h> using namespace std; int main(){int n,k;cin>>n>>k;vector<long long>a(n);long long hi=0;for(auto &v:a){string s;cin>>s;auto p=s.find('.');v=stoll(s.substr(0,p))*100+stoll(s.substr(p+1));hi=max(hi,v);}long long l=0;while(l<hi){long long m=(l+hi+1)/2,sum=0;for(auto v:a)sum+=v/m;if(sum>=k)l=m;else hi=m-1;}cout<<l/100<<'.'<<setw(2)<<setfill('0')<<l%100<<'\n';}
- 1