Wednesday, February 12, 2020

POJ.1064 Cable master

1.Problem
http://poj.org/problem?id=1064

2.Idea
Binary Search

3.Source
 int N, K;  
 double L[10004];  
 bool C(double x)  
 {  
      int num = 0;  
      for (int i = 0; i < N; i++) {  
           num += (int)(L[i] / x);  
      }  
      return num >= K;  
 }  
 void solve()  
 {  
      double lb = 0, ub = INF;  
      for (int i = 0; i < 100; i++) {  
           double mid = (lb + ub) / 2;  
           if (C(mid)) lb = mid;  
           else ub = mid;  
      }  
      printf("%.2f\n", floor(ub * 100) / 100);  
 }  
 int main()  
 {  
      cin >> N >> K;  
      for (int i = 0; i < N; i++) cin >> L[i];  
      solve();  
      return 0;  
 }  

No comments:

Post a Comment