注意题目这句话,Once you have each type of candies in a box, you want to pack those boxes into larger boxes, until only one box remains.

两个box合并后必须放入更大一个盒子

题目的有点类似huffman的前部分,此题用堆去做,由于priority_queue是用堆实现的,故可以直接使用

每次从堆中选取最小的两个进行合并即可

#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std; class BoxesDiv2{
public:
int round_up(int x){
for(int i = ; i <= ; ++ i){
if( <<i >= x ) return <<i;
}
return <<;
} int findSize(vector<int> candyCounts){
priority_queue<int,vector<int>,greater<int> > boxQueue;
for(int i = ; i < candyCounts.size(); ++ i){
boxQueue.push(round_up(candyCounts[i]));
}
while(boxQueue.size() != ){
int a = boxQueue.top();boxQueue.pop();
int b = boxQueue.top();boxQueue.pop();
boxQueue.push(max(a,b)*);
}
return boxQueue.top();
}
};

topcoder SRM 622 DIV2 BoxesDiv2的更多相关文章

  1. topcoder SRM 622 DIV2 FibonacciDiv2

    关于斐波那契数列,由于数据量比较小, 直接打表了,代码写的比较戳 #include <iostream> #include <vector> #include <algo ...

  2. Topcoder Srm 673 Div2 1000 BearPermutations2

    \(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...

  3. Topcoder Srm 671 Div2 1000 BearDestroysDiv2

    \(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...

  4. 求拓扑排序的数量,例题 topcoder srm 654 div2 500

    周赛时遇到的一道比较有意思的题目: Problem Statement      There are N rooms in Maki's new house. The rooms are number ...

  5. Topcoder srm 632 div2

    脑洞太大,简单东西就是想复杂,活该一直DIV2; A:水,基本判断A[I]<=A[I-1],ANS++; B:不知道别人怎么做的,我的是100*N*N;没办法想的太多了,忘记是连续的数列 我们枚 ...

  6. topcoder SRM 628 DIV2 BracketExpressions

    先用dfs搜索所有的情况,然后判断每种情况是不是括号匹配 #include <vector> #include <string> #include <list> # ...

  7. topcoder SRM 628 DIV2 BishopMove

    题目比较简单. 注意看测试用例2,给的提示 Please note that this is the largest possible return value: whenever there is ...

  8. Topcoder SRM 683 Div2 B

    贪心的题,从左向右推过去即可 #include <vector> #include <list> #include <map> #include <set&g ...

  9. Topcoder SRM 683 Div2 - C

    树形Dp的题,根据题意建树. DP[i][0] 表示以i为根节点的树的包含i的时候的所有状态点数的总和 Dp[i][1] 表示包含i结点的状态数目 对于一个子节点v Dp[i][0] = (Dp[v] ...

随机推荐

  1. MVC – 4.mvc初体验(2)

    5.显示学员列表 效果 数据表 5.1 首先,在文件夹Models新建一个新建项(W),选择ADO.NET 实体数据模型 (SingleTest.edmx) 5.2 建一个控制器,StudentsCo ...

  2. @ifconfig eth0|awk -F "[ :]+" 'NR==2{print $4 "/" $NF}'中"[ :]+" 是什么意思?@

    http://blog.csdn.net/zhuying_linux/article/details/6822987

  3. Oracle Redo Log

    http://blog.itpub.net/27039319/viewspace-2120623/ 11.2和11.2以下的区别:http://blog.itpub.net/27039319/view ...

  4. 无废话ExtJs 入门教程三[窗体:Window组件]

    无废话ExtJs 入门教程三[窗体:Window组件] extjs技术交流,欢迎加群(201926085) 1.代码如下: 1 <!DOCTYPE html PUBLIC "-//W3 ...

  5. 攻城狮在路上(叁)Linux(十四)--- 查阅文件内容

    常用命令:cat.tac.nl.more.less.head.tail.od... 一.直接查看文件内容:cat.tac.nl <==一次性全部读取 1.cat [-AbEnTv] 文件名 参数 ...

  6. 兼容所有浏览器的JS动态显示当前日期时间

    <script type="text/javascript"> function show_cur_times(){ //获取当前日期 var date_time = ...

  7. PHP计算程序运行时间的类

    <?php class runTime{ private $starTime; private $stopTime; private function getMicTime(){ $mictim ...

  8. phpcms v9最常用的22个调用代码

    新源网络工作室友情总结phpcms v9最常用的22个调用代码: 调用最新文章,带所在版块{pc:get sql="SELECT a.title, a.catid, b.catid, b.c ...

  9. Linux学习笔记(23) Linux备份

    1. 备份概述 Linux系统需要备份的数据有/root,/home,/var/spool/mail,/etc及日志等其他目录. 安装服务的数据需要备份,如apache需要备份的数据有配置文件.网页主 ...

  10. C#分布式缓存Couchbase使用

    目前C#业界使用得最多的 Cache 系统主要是 Memcached和 Redis. 这两个 Cache 系统可以说是比较成熟的解决方案,也是很多系统当然的选择. 一.简介 目前C#业界使用得最多的 ...