题意:科学家发现一种奇怪的东西,他们有重量weight,如果他们碰在一起,总重变成2*sqrt(m1*m2)。要求出最终的重量的最小值。

思路:每次选取质量m最大的两个stripy进行碰撞结合,能够得到最小的质量。所有只要维护一个优先队列就可以了

#include <iostream>
#include <cstdio>
#include <queue>
#include <math.h>
#include <cstring>
#include <algorithm>
using namespace std; priority_queue<double> que; int main()
{
int n;
scanf("%d", &n); for (int i = 0; i < n; i++) {
double m;
scanf("%lf", &m);
que.push(m);
} while (que.size() > 1) {
double m1 = que.top();
que.pop();
double m2 = que.top();
que.pop();
que.push(2 * sqrt(m1 * m2));
} printf("%.3f\n", que.top()); return 0;
}

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: 18198   Accepted: 8175 Descrip ...

  4. POJ 1862 Stripies (哈夫曼树)

    Stripies Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10263   Accepted: 4971 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

    每次合并最大的两个,优先级队列维护一下. 输出的时候%.3lf G++会WA,C++能AC,改成%.3f,都能AC. #include<cstdio> #include<cstrin ...

  8. poj 3431 Expedition 优先队列

    poj 3431 Expedition 优先队列 题目链接: http://poj.org/problem?id=2431 思路: 优先队列.对于一段能够达到的距离,优先选择其中能够加油最多的站点,这 ...

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

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

随机推荐

  1. jdk8中奖Date转换为String格式的方法

    public static String getLocalDateStr(Date date,String formatter) { DateTimeFormatter dateTimeFormatt ...

  2. (五)bootloader 启动 ucore os

    Lab1 : bootloader 启动 ucore os 一.内容提要 x86启动顺序 C函数调用 gcc内联汇编(inline assembly) x86-32下的中断处理 小结 二.x86启动顺 ...

  3. python -- 算法

    给定四个数字,找出不重复的排列组合可能 # 黑魔法方法,还纳闷 lambda 不能 yield 其实把 [] 改为小括号即是生成器啦 func = lambda num_tuple:((i,j,k,n ...

  4. dragula 一个 JavaScript 库,实现了网页上的拖放位置

    如图,把上面红蓝色拖放到下面 使用方法比较简单,如下代码: <link href='dist/dragula.css' rel='stylesheet' type='text/css' /> ...

  5. Linux - 文件操作

    touch file # 创建空白文件 rm -rf 目录名 # 不提示删除非空目录(-r:递归删除 -f强制) dos2unix # windows文本转linux文本 unix2dos # lin ...

  6. Java EE之Struts2-2.5配置

    开学以来,已经三周了.Java EE却不太走心,于是,这几日空杯心态,重新学习.复习了Java SE和Java Web开发技术,然后入手Struts2.为了使用最新版本的Structs2,我去官网下载 ...

  7. Database学习 - mysql 数据库 外键

    外键 外键约束子表的含义:如果在父表中赵达不到候选键,则不允许在子表上进行insert/update 外键预约对父表的含义:在父表上进行update/delete以更新或删除子表中有一条或多条对应匹配 ...

  8. linux相关设置

    mysql开机自启: [root@workstudio system]# systemctl enable mysqld

  9. 教你如何使用android studio发布release 版本【转】

    原文链接 想必还有人对如何在Android studio (以下简称as)发布release版本的app而狂刷百度吧?都是过来人,我很理解这种心情,百度到的基本是半成品,为什么这么说呢?百度一下,你就 ...

  10. Latex 公式颜色

    如何给这个公式加上颜色? 解决方法: \usepackage{xcolor} \begin{align}   \textcolor{red}{\int_a^b}\textcolor{blue}{f(x ...