题意:
现在有很多粒子,两个碰撞之后形成一个粒子并且会减小质量,求最小值量。
思路:
很简单,选出最大的两个碰撞质量减少最多。
不过也复习了一下优先队列与结构体的使用。
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdio>
using namespace std;
class Node
{
public:
double x;
friend bool operator< (Node a,Node b)
{
return a.x < b.x;
}
}seed[200];
int main()
{
//freopen("in.txt","r",stdin);
int n;
Node temp1,temp2;
scanf("%d",&n);
priority_queue<Node>Q;
for(int i = 0;i < n; i++){
scanf("%lf",&seed[i].x);
Q.push(seed[i]);
}
while(!Q.empty()){
temp1 = Q.top();
Q.pop();
if(Q.empty())
break;
temp2 = Q.top();
Q.pop();
double t = 2.0*sqrt(temp1.x*temp2.x);
temp1.x = t;
Q.push(temp1);
}
printf("%.3f\n",temp1.x);
return 0;
}