每次合并最大的两个,优先级队列维护一下。

输出的时候%.3lf G++会WA,C++能AC,改成%.3f,都能AC。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std; int n,s;
priority_queue<double>Q; int main()
{
while(~scanf("%d",&n))
{
while(!Q.empty())Q.pop();
for(int i=; i<=n; i++)
{
double x;
scanf("%lf",&x);
Q.push(x);
} s=n;
if(s==)printf("%.3f\n",Q.top());
else
{
while()
{
double num1=Q.top();
Q.pop();
s--;
double num2=Q.top();
Q.pop();
s--;
Q.push(*sqrt(num1*num2));
s++;
if(s==)
{
printf("%.3f\n",Q.top());
break;
}
}
}
}
return ;
}

POJ 1862 Stripies的更多相关文章

  1. poj 1862 Stripies/优先队列

    原题链接:http://poj.org/problem?id=1862 简单题,贪心+优先队列主要练习一下stl大根堆 写了几种实现方式写成类的形式还是要慢一些... 手打的heap: 1: #inc ...

  2. POJ 1862 Stripies 贪心+优先队列

    http://poj.org/problem?id=1862 题目大意: 有一种生物能两两合并,合并之前的重量分别为m1和m2,合并之后变为2*sqrt(m1*m2),现在给定n个这样的生物,求合并成 ...

  3. POJ 1862 Stripies (哈夫曼树)

    Stripies Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10263   Accepted: 4971 Descrip ...

  4. POJ 1862 Stripies【哈夫曼/贪心/优先队列】

    Stripies Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18198   Accepted: 8175 Descrip ...

  5. STL 训练 POJ - 1862 Stripies

    Description Our chemical biologists have invented a new very useful form of life called stripies (in ...

  6. POJ 1862 Stripies#贪心(水)

    (- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cmath> #include<algorithm ...

  7. POJ 1862 Stripies 【优先队列】

    题意:科学家发现一种奇怪的东西,他们有重量weight,如果他们碰在一起,总重变成2*sqrt(m1*m2).要求出最终的重量的最小值. 思路:每次选取质量m最大的两个stripy进行碰撞结合,能够得 ...

  8. POJ 1862 &amp; ZOJ 1543 Stripies(贪心 | 优先队列)

    题目链接: PKU:http://poj.org/problem?id=1862 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...

  9. 【贪心】Stripies POJ 1862

    题目描述:http://poj.org/problem?id=1862 题目大意:你有n个数要合并,每两个数x,y合并后得到2*sqrt(x*y).求最后留下的一个数的最小值. 每合并一次,就会有数被 ...

随机推荐

  1. 函数FindFirstFile

    文件查找 Struct Lnode{ Char table[256];         //保存文件夹名 Struct Lnode*next; } 加文件夹入链表 Lnode *newList; Vo ...

  2. HDU-1301 Jungle Roads(最小生成树[Prim])

    Jungle Roads Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  3. list遍历

     一.对List的遍历有三种方式            List<String>    list    =    new    ArrayList<String>();    ...

  4. android ApplicationContext Context Activity 内存的一些学习

    Android中context可以作很多操作,但是最主要的功能是加载和访问资源. 在android中有两种context,一种是application context,一种是activity cont ...

  5. Java 多态,重载,重写

    1.多态(polymorphism): 多态是指程序中定义的引用变量所指向的具体类型和通过该引用变量发出的方法调用在编程时并不确定,而是在程序运行期间才确定,即一个引用变量倒底会指向哪个类的实例对象, ...

  6. CakePHP下使用paginator需要对多个字段排序的做法

      原文:http://blog.csdn.net/kunshan_shenbin/article/details/7644603  CakePHP下使用paginator需要对多个字段排序的做法 2 ...

  7. 遍历Map key-value的两种方法

    以前遍历Map key-value比较习惯的方式是先获取Map中的所有key值,然后根据key,依次从Map中去数据,基本方式如下: Map<String,String> testData ...

  8. 会员登录HTML

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><!DOCTYPE html PUBLIC "-//W ...

  9. aspx 文件上传和下载,多文件上传

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MultiFileUpload. ...

  10. Python3基础 list(zip()) 将两个列表打包起来

    镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...