(贪心和优先队列) POJ1862 Stripies
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 21506 | Accepted: 9478 |
Description
You are to write a program that will help them to answer this question. You may assume that 3 or more stipies never collide together.
Input
Output
Sample Input
3
72
30
50
Sample Output
120.000 贪心和优先队列,先选择最大的两个数合并,然后加入队列,可以用priority_queue(),默认为最大堆。
C++代码(只能用C++编辑器过,G++却会WA)
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
priority_queue<double> pq;
int N;
scanf("%d",&N);
double m;
int t = N;
while(t--){
scanf("%lf",&m);
pq.push(m);
}
int k = N - ;
double a,b;
while(k--){
a = pq.top();
pq.pop();
b = pq.top();
pq.pop();
pq.push( * sqrt(a*b));
}
printf("%.3lf\n",pq.top());
pq.pop();
return ;
}
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
priority_queue<double> pq;
int N;
scanf("%d",&N);
double m;
int t = N;
while(t--){
scanf("%lf",&m);
pq.push(m);
}
double a,b,tmp;
while(!pq.empty()){
a = pq.top();
pq.pop();
if(pq.empty()){
printf("%.3lf\n",a);
break; //要加break
}
b = pq.top();
pq.pop();
tmp = * sqrt(a*b);
pq.push(tmp);
}
return ;
}
(贪心和优先队列) POJ1862 Stripies的更多相关文章
- Luogu 1090 合并果子(贪心,优先队列,STL运用)
Luogu 1090 合并果子(贪心,优先队列,STL运用) Description 在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多决定把所有的果子合成一堆. 每 ...
- bzoj1528 sam-Toy Cars(贪心,优先队列)
「BZOJ1528」[POI2005] sam – Toy Cars Description Jasio 是一个三岁的小男孩,他最喜欢玩玩具了,他有n 个不同的玩具,它们都被放在了很高的架子上所以Ja ...
- POJ1862 Stripies 贪心 B
POJ 1862 Stripies https://vjudge.net/problem/POJ-1862 题目: Our chemical biologists have invented ...
- CF #374 (Div. 2) D. 贪心,优先队列或set
1.CF #374 (Div. 2) D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...
- sgu548 Dragons and Princesses 贪心+优先队列
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=548 题目意思: 有一个骑士,要经过n个房间,开始在第一个房间,每个房间里面有龙或者 ...
- poj3190区间类贪心+优先队列
题意:每个奶牛产奶的时间为A到B,每个奶牛产奶时要占用一间房子,问n头奶牛产奶共需要多少房子,并输出每头奶牛用哪间房子 分析:这题就是一个裸的贪心,将奶牛按开始时间进行排序即可,但考虑一下数据范围,我 ...
- 【贪心算法】POJ-1862 简单哈夫曼
一.题目 Description Our chemical biologists have invented a new very useful form of life called stripie ...
- 【BZOJ 3661】 Hungry Rabbit (贪心、优先队列)
3661: Hungry Rabbit Time Limit: 100 Sec Memory Limit: 512 MBSec Special JudgeSubmit: 67 Solved: 4 ...
- 2015多校第6场 HDU 5360 Hiking 贪心,优先队列
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5360 题意:给定n个人,现在要邀请这些人去远足,但每个人同意邀请的条件是当前已经同意去远足的人数c必须 ...
随机推荐
- javascript中关于value的一个小知识点(value既是属性也是变量)
今天在学习input的value值时,发现这么一个小知识点,以前理解不太透彻 [1]以下这种情况是常见情况,会弹出“测试内容” <input type="button" va ...
- vhdl 边沿
rising_eage falling_eage clock'event and clock='1' 两种方式
- How to write to an event log by using Visual C#
using System; using System.Diagnostics; namespace WriteToAnEventLog_csharp { /// Summary description ...
- 训练赛-Eyad and Math
题意:给你四个数,求出a^b是否小于c^d,是的话输出<,否则输出>; 思路:因为数据很大,所以我们需要降低数据的规模,比如用一个log10()函数,这就能解决了,注意,要用scanf输入 ...
- 洛谷P2858奶牛零食 题解
题目 这个题一开始能看出来是一道动态规划的题目,但是并不知道如何写状态转移方程,但是我们可以想一想这个题应该是一道区间DP,而区间DP的特点就是状态转移方程一般跟该区间的左节点和右节点或者中间断点有关 ...
- [POJ2976] Dropping tests
传送门:>Here< 题意:给出长度相等的数组a和b,定义他们的和为$\dfrac{a_1+a_2+...+a_n}{b_1+b_2+...+b_n}$.现在可以舍弃k对元素(一对即$a[ ...
- [SP1043] GSS1 - Can you answer these queries I
传送门:>Here< 题意:求区间最大子段和 $N \leq 50000$ 包括多组询问(不需要支持修改) 解题思路 线段树的一道好题 我们可以考虑,如果一组数据全部都是正数,那么问题等同 ...
- Appium+python+html生成饼图测试报告
历时三周这个小框架终于正式运行了,git源码地址;https://github.com/jiyanjiao/AutoTEST/tree/master/qingqi_driver_app 报告如图:
- eclipse中git推送上传错误 没有足够的数据写入
Can't connect to any repository: https://github.com/jiashubing/test.git (https://github.com/jiashubi ...
- JeeSite 部署到linux服务器
1.打包 改数据库连接 打包war包https://www.cnblogs.com/wdw31210/p/9878422.html 2.上传到linux 服务器的tomcat/webapps/ 下 安 ...