Sunday, January 12, 2020

POJ.1862 Stripies

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

2.Idea
Pick the biggest 2 value, and process them, return to queue.

3.Source
 int n;  
 double a[111];  
 priority_queue<double> q;  
 int main()  
 {  
      cin >> n;  
      for (int i = 0; i < n; i++) {  
           cin >> a[i];  
           q.push(a[i]);  
      }  
      for (int i = n - 1; i > 0; i--) {  
           double A = q.top(); q.pop();  
           double B = q.top(); q.pop();  
           q.push(2 * sqrt(A * B));  
      }  
      cout << fixed << std::setprecision(3) << q.top() << endl;  
      return 0;  
 }  

No comments:

Post a Comment