Luogu: P1577 Cut the rope (two points, popularization/improvement-)

topic:

Insert picture description here

Analysis: directly use the template to solve a problem.

1. The result should be 0.01 accuracy, then 0.001 when updating.

2. Requirements:

Insert picture description here
Don't waste time by adding a 0.2lf to yourself.

Code:

#include<bits/stdc++.h>
using namespace std;
int m,k;
double A[10005];
int main()
{
    
    
 cin>>m>>k;
 double maxx=-1;
 for(int i=0;i<m;i++)
 {
    
    
  cin>>A[i];
  maxx=max(maxx,A[i]);
 }
 double a=0.01,b=maxx;
 while(a<=b)
 {
    
    
  double c=(a+b)/2;
  int all=0;
  for(int i=0;i<m;i++)
  {
    
    
   all+=(int)(A[i]/c);
  }
  if(all>=k)
  {
    
    
   a=c+0.0001;
  }
  else b=c-0.0001;
 }
 printf("%lf",a-0.0001);
}

Guess you like

Origin blog.csdn.net/weixin_42721412/article/details/108520598