POJ 1862 Stripies
每次合并最大的两个,优先级队列维护一下。
输出的时候%.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的更多相关文章
- poj 1862 Stripies/优先队列
原题链接:http://poj.org/problem?id=1862 简单题,贪心+优先队列主要练习一下stl大根堆 写了几种实现方式写成类的形式还是要慢一些... 手打的heap: 1: #inc ...
- POJ 1862 Stripies 贪心+优先队列
http://poj.org/problem?id=1862 题目大意: 有一种生物能两两合并,合并之前的重量分别为m1和m2,合并之后变为2*sqrt(m1*m2),现在给定n个这样的生物,求合并成 ...
- POJ 1862 Stripies (哈夫曼树)
Stripies Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10263 Accepted: 4971 Descrip ...
- POJ 1862 Stripies【哈夫曼/贪心/优先队列】
Stripies Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 18198 Accepted: 8175 Descrip ...
- STL 训练 POJ - 1862 Stripies
Description Our chemical biologists have invented a new very useful form of life called stripies (in ...
- POJ 1862 Stripies#贪心(水)
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cmath> #include<algorithm ...
- POJ 1862 Stripies 【优先队列】
题意:科学家发现一种奇怪的东西,他们有重量weight,如果他们碰在一起,总重变成2*sqrt(m1*m2).要求出最终的重量的最小值. 思路:每次选取质量m最大的两个stripy进行碰撞结合,能够得 ...
- POJ 1862 & ZOJ 1543 Stripies(贪心 | 优先队列)
题目链接: PKU:http://poj.org/problem?id=1862 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...
- 【贪心】Stripies POJ 1862
题目描述:http://poj.org/problem?id=1862 题目大意:你有n个数要合并,每两个数x,y合并后得到2*sqrt(x*y).求最后留下的一个数的最小值. 每合并一次,就会有数被 ...
随机推荐
- instanceof实例和prototype
var arr=[1,3,2];alert(arr instanceof Array); 返回true: 对于继承譬如一个Drag()拖拽的继承,我想加一个限制范围的拖拽 我需要写一个新的函数 fun ...
- IE6 下 输入类型表单控件背景问题
.box input{background:url(img/1.jpg) fixed} <body> <div class="box"> <input ...
- HDU1969:Pie(二分)
Pie Time Limit : 5000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissio ...
- angularjs model.service vs provider vs factory?
<!DOCTYPE html> <html ng-app="app"> <head> <script src="http://c ...
- 十二月总结-and-2016年终总结
回顾 今天是2016的最后一天了,所以今天来做一个年终总结是最好不过的了.各种期末考试随着而来,也就意味着在工大的第一个学期马上结束了.回顾一下这一年所获得或者失去的一些东西: 2月份在家焦虑的等待着 ...
- EF5修改edmx表结构保存后不自动更新tt (转)
http://blog.csdn.net/panderman/article/details/8172968 不知道这算不算一个bug,当你新建一个从数据库生成的edmx时,他能正确的生成所有的tt文 ...
- hdu_3886_Final Kichiku “Lanlanshu”(数位DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3886 题意:这题的题意有点晦涩难懂,大概意思就是给你一个区间,让你找一些满足递增递减条件的数,举个列: ...
- java工程开发之图形化界面之(第一课)
下面我们先上代码: package 一个事例图形小应用程序; import javax.swing.JApplet; import java.awt.Graphics; public class 绘制 ...
- 转 Android HTTPS详解
目录(?)[-] 前言 HTTPS原理 SSLTLS协议作用 基本的运行过程 握手阶段的详细过程 客户端发出请求ClientHello 服务器回应ServerHello 客户端回应 服务器的最后回应 ...
- 处理Easyui的Datagrid无法及时刷新问题
在Easyui中打打开窗口dialog控件,当做完修改操作之后,关闭dialog控件刷新Datagrid,有时候无法及时刷新. 1.JavaScript中的代码 function doEdit(){ ...