POJ3253 Fence Repair(贪心)
分割木板的顺序是自由的,所以每次选择两块最短的板,组合在一起,增加队列,原来两个板出队,直到队列中为空或者仅仅剩下一个板时结束。这里使用优先队列较为方便。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll __int64
using namespace std; int len[20005]; int main()
{
//freopen("d:\\test.txt","r",stdin);
int n;
ll ans=0;
cin>>n;
priority_queue<int,vector<int>,greater<int> >q;//最小元素在队头
for(int i=0;i<n;i++)
{
cin>>len[i];
q.push(len[i]);
}
while(!q.empty())
{
int t1=q.top();
q.pop();
if(!q.empty())
{
int t2=q.top();
q.pop();
ans+=t1+t2;
q.push(t1+t2);
}
else break;
}
printf("%I64d\n",ans);
return 0;
}
POJ3253 Fence Repair(贪心)的更多相关文章
- POJ 3253 Fence Repair 贪心 优先级队列
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 77001 Accepted: 25185 De ...
- POJ 3253 Fence Repair (贪心)
Fence Repair Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- 优先队列 poj3253 Fence Repair
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 51411 Accepted: 16879 De ...
- Poj3253 Fence Repair (优先队列)
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 67319 Accepted: 22142 De ...
- poj-3253 fence repair(贪心题)
题目描述: Farmer John wants to repair a small length of the fence around the pasture. He measures the fe ...
- poj3253 Fence Repair(贪心+哈夫曼 经典)
https://vjudge.net/problem/POJ-3253 很经典的题,运用哈夫曼思想,想想很有道理!! 具体实现还是有点绕人,最后被long long卡了一下,看数据大小的时候单纯相乘了 ...
- POJ3253 Fence Repair【贪心】
我们的小伙伴Bingo真的很调皮,他在上课的路上看到树上有个鸟窝,他就想去把他捅下来,但是鸟窝很高他够不到,于是他就到处找木棍,想把这些木棍接在一起,然后去捅鸟窝.他一共找了N跟木棍 (1 ≤ N ≤ ...
- poj3253 Fence Repair
http://poj.org/problem?id=3253 Farmer John wants to repair a small length of the fence around the pa ...
- poj3253 Fence Repair【哈夫曼树+优先队列】
Description Farmer John wants to repair a small length of the fence around the pasture. He measures ...
随机推荐
- JDBC批量操作
/** * 批量执行预定义模式的SQL */ public static void exeBatchParparedSQL() { ...
- 在线获取访客QQ号码的原理及实现方法
原文地址:http://www.piaoyi.org/network/get-qq-haoma-js.html 正 文: 最近,飘易收到不少在线获取网站访客QQ号码的促销推广邮件,有不少商用网站挖掘了 ...
- OpenLayers实现覆盖物选择信息提示
var map; function init() { map = new OpenLayers.Map("map",{projection:"EPSG:3857" ...
- nyoj 1238 最少换乘(dijkstra)
描述 欧洲某城是一个著名的旅游胜地,每年都有成千上万的人前来观光旅行.Dr. Kong决定利用暑假好好游览一番.. 年轻人旅游不怕辛苦,不怕劳累,只要费用低就行.但Dr. Kong年过半百,他希望乘坐 ...
- HttpContext详解【转】
HttpContext 类:封装有关个别 HTTP 请求的所有 HTTP 特定的信息. 在处理请求执行链的各个阶段中,会有一个对象在各个对象之间进行传递,也即会保存请求的上下文信息,这个对象就是Htt ...
- MVC 5 + EF 6
(一) ??运算符 C#中两个问号(“?”)的作用是判断“?”左边的对象是否为null,如果不为null则使用“?”左边的对象,如果为null则使用“?”右边的对象. (二)VS安装Entity Fr ...
- MUD江湖_MUD文字游戏_MUD五指_武林群侠_北侠_夺宝江湖_书剑_文字江湖游戏_MUD游戏下载
MUD江湖_MUD文字游戏_MUD五指_武林群侠_北侠_夺宝江湖_书剑_文字江湖游戏_MUD游戏下载 武侠类手机文字游戏,经典再现高度自由玩法宠物 自制装备 师徒自立门派 自造武功欢迎来玩 Q群 1 ...
- c# 中的 Trim
1. 让用户输入字符串 并且判断是否是 'yes'(无关大小写) Console.WriteLine("input a string"); string userResponse ...
- python---连接MySQL第四页
python缓存结果集式的cursor可以用来提高性能. 例子: #!conding:utf-8 from mysql.connector import errorcode import mysql. ...
- 怎查看linux系统的位数
# uname -a x86_64则说明你是64位内核, 跑的是64位的系统. i386, i686说明你是32位的内核, 跑的是32位的系统