Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:为什么将初始左端点设置为1就WA呢In Reply To:为什么将初始左端点设置为1就WA呢 Posted by:1069890 at 2019-08-05 23:58:49 > #include<iostream> > #include<cstring> > #include<math.h> > #include<stdlib.h> > #include<cstring> > #include<cstdio> > #include<utility> > #include<algorithm> > #include<map> > #include<iomanip> > using namespace std; > long long int n,k; > const int maxn=100005; > const double inf=200005.0; > double ary[maxn]; > > int div(double x){//每条长度为x可以分为几段 > int ans=0; > for(int i=1;i<=n;i++){ > ans+=(int)(ary[i]/x); > } > return ans>=k; > } > > > int main() > { > ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); > //freopen("input.txt","r",stdin); > while(cin>>n>>k){ > for(int i=1;i<=n;i++)cin>>ary[i]; > > sort(ary+1,ary+1+n); > //这里left>0会错。。。 > double left=0,right=ary[n]; > > double mid=0; > for(int i=1;i<=100;i++){ > mid=(left+right)/2; > //分割段数过多说明木板长度小,所以这里是左端点 > if(div(mid))left=mid; > else right=mid; > } > printf("%.2f\n",floor(left*100)/100); > > } > return 0; > } 假设10条绳子初始长度都是1,要切成100条绳子,那么结果应该是0.10 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator