题意:科学家发现一种奇怪的东西,他们有重量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. Linux 命令详解(八)Systemd 入门教程:实战篇

    Systemd 入门教程:实战篇 http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html

  2. C 编译过程浅析

    From where i stand, there are two programmig languages in the world, which is C lang and the other. ...

  3. SysTick_CLKSourceConfig 这个函数

    systick的寄存器说明是在<Cortex M3权威指南>里说明了! 其实是有选择的,只是默认是AHB/8.通过设置systick的CTRL寄存器的bit2来设置时钟,设置如下: bit ...

  4. PreparedStatement 基于mysql数据库做分页查询和统计查询

    分页查询: 统计查询:

  5. spoj gss1 gss3

    传送门 gss1 gss3 spoj gss系列=最大字段和套餐 gss1就是gss3的无单点修改版 有区间查询和单点修改,考虑用线段树维护 我们要维护区间权值和\(s\),区间最大前缀和\(xl\) ...

  6. 第5月第7天 php slim

    1. <?php require 'Slim/Slim.php'; require 'DBManagement.php'; \Slim\Slim::registerAutoloader(); $ ...

  7. vscode 配置Git

    步骤: 下载Git客户端 配置环境变量 设置vscode与Git的关联 重启 步骤一: 该网址,下载即可. https://git-scm.com/downloads 步骤二: 计算机 > 属性 ...

  8. TIdHTTP get参数带中文解决方法--请求报文

    Post 看起来稍微复杂先,暂不讨论.post 目前按照一般方法有中文名也可以. 拼接时:pointname=九记餐厅&begintime=2017-03-01 00:00:00& 有 ...

  9. OGG实现两台Oracle数据库的同步

    今天通过最简单的一个例子,给大家讲解下 goldengate 实现两台Oracle数据库的同步.内容如下:1.配置数据库信息.2.安装golden gate.3.配置golden gate.4.测试同 ...

  10. 统一过程模型(UP)

    1.前言 本文主要对迭代开发的一种方法 统一过程(UP),进行概要说明,以作为<UML和模式应用>这本书的补充. 2. 统一过程概述 统一过程 统一过程(RUP/UP,Rational U ...