POJ 1862 Stripies【哈夫曼/贪心/优先队列】
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 18198 | Accepted: 8175 |
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
Source
【分析】:类似于哈弗曼树的方法,每次选举两个当前最大的数值进行运算,直到剩下一个物品。使用优先队列处理比较方便。
#include<iostream>
#include<stdio.h>
#include<vector>
#include<queue>
#include<cmath>
using namespace std; #define LL long long
using namespace std;
const int N = +;
int n;
double L;
double a,b;
priority_queue<double> q;
int main()
{
cin>>n; for(int i=;i<n;i++)
{
cin>>L;
q.push(L);
}
while(q.size()>)
{
a=q.top();q.pop(); b=q.top();q.pop(); q.push(*sqrt(a*b));
}
printf("%.3f\n",q.top()); return ;
}
POJ 1862 Stripies【哈夫曼/贪心/优先队列】的更多相关文章
- poj3253 Fence Repair【哈夫曼树+优先队列】
Description Farmer John wants to repair a small length of the fence around the pasture. He measures ...
- poj 1862 Stripies/优先队列
原题链接:http://poj.org/problem?id=1862 简单题,贪心+优先队列主要练习一下stl大根堆 写了几种实现方式写成类的形式还是要慢一些... 手打的heap: 1: #inc ...
- Fence Repair POJ - 3253 哈夫曼思想 优先队列
题意:给出一段无限长的棍子,切一刀需要的代价是棍子的总长,例如21切一刀 变成什么长度 都是代价21 列如7切成5 和2 也是代价7题解:可以利用霍夫曼编码的思想 短的棍子就放在底层 长的尽量切少一次 ...
- poj 3253 哈夫曼贪心
http://poj.org/problem?id=3253 题意: FJ需要修补牧场的围栏,他需要 N 块长度为 Li 的木头(N planks of woods).开始时,FJ只有一块无限长的木板 ...
- [POJ 1521]--Entropy(哈夫曼树)
题目链接:http://poj.org/problem?id=1521 Entropy Time Limit: 1000MS Memory Limit: 10000K Description A ...
- 【PTA 天梯赛训练】修理牧场(哈夫曼树+优先队列)
农夫要修理牧场的一段栅栏,他测量了栅栏,发现需要N块木头,每块木头长度为整数Li个长度单位,于是他购买了一条很长的.能锯成N块的木头,即该木头的长度是Li的总和. 但是农夫自己没有锯子,请 ...
- 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 3253 Fence Repair (哈夫曼树 优先队列)
题目:http://poj.org/problem?id=3253 没用long long wrong 了一次 #include <iostream> #include<cstdio ...
随机推荐
- javascript类式继承模式#4——共享原型
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 剑指Offer - 九度1510 - 替换空格
剑指Offer - 九度1510 - 替换空格2013-11-29 20:53 题目描述: 请实现一个函数,将一个字符串中的空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之 ...
- Object Pascal中文手册 经典教程
Object Pascal 参考手册 (Ver 0.1)ezdelphi@hotmail.com OverviewOverview(概述)Using object pascal(使用 object p ...
- 【Multiply Strings】cpp
题目: Given two numbers represented as strings, return multiplication of the numbers as a string. Note ...
- ADB push 和ADB pull命令
adb push命令 :从电脑上传送文件到手机: adb pull命令 :从手机传送文件到电脑上
- C++树的建立和遍历
#include<iostream.h> typedef char TElemtype; typedef struct Btree { TElemtype data; struct Btr ...
- Python 3.x的编码问题
Python 3的源码.py文件的默认编码方式为UTF-8(Python 2.x的默认编码格式为unicode). encode的作用,使我们看到的直观的字符转换成计算机内的字节形式. decode刚 ...
- PHP文件开头session_start()
session_start(); 告诉服务器使用session.一般来说,php是不会主动使用session的. 不过可以设置php.ini中的session.auto_start=1来自动对每个请求 ...
- vue & lifecycle methods & this bug & ES6 Arrow function & this bind bug
vue & lifecycle methods & this bug ES6 Arrow function & this bind bug bad fetchTableData ...
- 使用C#创建windows服务程序
创建windows服务项目 一.创建服务 1.文件->新建->项目->windows桌面->windows服务,修改你要的项目名称.我这不改名,仍叫WindowsService ...