POj3253 Fence Repair
题目链接 点击打开链接
#include<iostream>
#include<queue>
using namespace std;
int main()
{
int a[20010];
int n;
priority_queue<int,vector<int>,greater<int> > Q;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
Q.push(a[i]);
}
long long int ans=0;
while(Q.size()>1)
{
int a=Q.top();
Q.pop();
int b=Q.top();
Q.pop();
ans=ans+a+b;
Q.push(a+b);
}
cout<<ans<<endl;
}
poj1862
Stripies
题目链接 点击打开链接
#include<iostream>
#include<stdio.h>
#include<iomanip>
#include<cmath>
#include<queue>
using namespace std;
int main()
{
int n;
double a[110];
cin>>n;
priority_queue<double> Q;
for(int i=1;i<=n;i++)
{
cin>>a[i];
Q.push(a[i]);
}
while(Q.size()>1)
{
double b=Q.top();
Q.pop();
double c=Q.top();
Q.pop();
double d=2*sqrt(b*c*1.0);
Q.push(d);
}
cout<<setiosflags(ios::fixed)<<setprecision(3)<<Q.top()<<endl;
}