POJ 1862
来源:互联网 发布:pkpm钢结构计算软件 编辑:程序博客网 时间:2024/06/06 01:30
题意:Stripies这货我就说成是小虫子啦(⊙o⊙)…,也就是说两只小虫(m1,m2)相遇后会合体,合体后的质量是m=2*sqrt(m1*m2)。题目要求输入小虫数量和每只小虫质量,要求输出小虫合体后的最后质量。
思路:现将小虫的质量从大到小排列,再按照前面的排列顺序从头到尾逐对计算。
代码:
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<iomanip>
usingnamespace std;
intcompare(const void*a,const void*b){return *(double*)b-*(double*)a;}
intmain()
{
int n;
double *a;
while(cin>>n)
{
a=new double[n];
for(int i=0;i<n;i++)
cin>>a[i];
qsort(a,n,sizeof(double),compare);
for(int i=0;i<n-1;i++)
a[i+1]=2.0*sqrt(a[i]*a[i+1]);
cout<<fixed<<setprecision(3)<<a[n-1]<<endl;
}
return 0;
}
#include<cstdlib>
#include<cmath>
#include<iomanip>
using
int
int
{
}
- POJ 1862
- poj 2488
- POJ 3299
- poj 1905
- POJ 2485 Highways
- POj 1017 Packets
- poj 1020 搜索
- poj 3278 宽搜
- poj 1426 宽搜
- poj 1925 Spiderman
- poj 3259 Wormholes
- POJ 2160 BOX
- POJ 2190 ISBN
- poj 3299 humidex
- poj 2253 Frogger
- poj 2485 Highways
- poj 3041 Asteroids
- poj 数论 1845
- C++学习书籍推荐
- POJ 1607
- POJ 1657
- POJ 1674
- POJ 1799
- POJ 1862
- POJ 1906
- POJ 1922
- POJ 1929
- POJ 1969
- POJ 2000
- POJ 2005
- POJ 2017
- POJ 2070