[topcoder]BoxesDiv2
https://community.topcoder.com/stat?c=problem_statement&pm=13192
#include <vector>
#include <queue>
#include <functional>
using namespace std; class BoxesDiv2
{
public:
vector<int> power2;
int findSize(vector <int> candyCounts)
{
priority_queue<int, vector<int>, greater<int> > q;
power2.clear();
int tmp = 1;
for (int i = 0; i < 32; i++)
{
power2.push_back(tmp);
tmp *= 2;
}
int size = candyCounts.size();
for (int i = 0; i < size; i++)
{
int x = leastPower(candyCounts[i]);
q.push(x);
} while (q.size() > 1)
{
int a = q.top();
q.pop();
int b = q.top();
q.pop();
int bigger = max(a,b);
q.push(bigger*2);
}
if (!q.empty())
{
return q.top();
}
else
{
return -1;
}
} int leastPower(int x)
{
int i = 0;
while (x > power2[i])
i++;
return power2[i];
}
};
[topcoder]BoxesDiv2的更多相关文章
- topcoder SRM 622 DIV2 BoxesDiv2
注意题目这句话,Once you have each type of candies in a box, you want to pack those boxes into larger boxes, ...
- TopCoder kawigiEdit插件配置
kawigiEdit插件可以提高 TopCoder编译,提交效率,可以管理保存每次SRM的代码. kawigiEdit下载地址:http://code.google.com/p/kawigiedit/ ...
- 记第一次TopCoder, 练习SRM 583 div2 250
今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...
- TopCoder比赛总结表
TopCoder 250 500 ...
- Topcoder几例C++字符串应用
本文写于9月初,是利用Topcoder准备应聘时的机试环节临时补习的C++的一部分内容.签约之后,没有再进行练习,此文暂告一段落. 换句话说,就是本文太监了,一直做草稿看着别扭,删掉又觉得可惜,索性发 ...
- TopCoder
在TopCoder下载好luncher,网址:https://www.topcoder.com/community/competitive%20programming/ 选择launch web ar ...
- TopCoder SRM 596 DIV 1 250
body { font-family: Monospaced; font-size: 12pt } pre { font-family: Monospaced; font-size: 12pt } P ...
- 求拓扑排序的数量,例题 topcoder srm 654 div2 500
周赛时遇到的一道比较有意思的题目: Problem Statement There are N rooms in Maki's new house. The rooms are number ...
- TopCoder SRM 590
第一次做TC,不太习惯,各种调试,只做了一题...... Problem Statement Fox Ciel is going to play Gomoku with her friend ...
随机推荐
- 利用Apply的参数数组化来提高代码的优雅性,及高效性
利用Apply的参数数组化来提高代码的优雅性,及高效性 Function.apply()在提升程序性能方面的技巧 我们先从Math.max()函数说起,Math.max后面可以接任意个参数,最后返回所 ...
- php对数组排序代码
php对数组排序,介绍了和php,有关的知识.技巧.经验,和一些php源码等. 对数组排序 usort() 函数使用用户自定义的函数对数组排序. */ function cmp($a, $b) //用 ...
- PHP CodeIgniter(CI)去掉 index.php
去掉CodeIgniter(CI)默认url中的index.php的步骤: 1.打开apache的配置文件,conf/httpd.conf : LoadModule rewrite_module mo ...
- Odoo 库存管理-库存移动(Stock Move)新玩法
库存移动(Stock Move)新玩法 Odoo的库存移动不仅仅是存货在两个“存货地点”之间的移动的基本概念了,他们可以被“串联”在一起,可以用来生成或改变其对应的拣货单 (Picking).链式库存 ...
- apache common包下的StringUtils的join方法
apache common包下的StringUtils的join方法: 关键字:java string array join public static String join(Iterator it ...
- mysql基本知识---20151127-1
2015年11月27日,作为PHPer的我开始全面学习mysql数据库. 基本语法: 1.连接服务器: mysql>mysql -h host -u root -p 回车 输入密码(本地环境可以 ...
- 利用ddmlib 实现 PC端与android手机端adb forword socket通信(转)
上篇文章讲了PC与android手机连接的办法 ,通过java调用系统命令执行adb命令操作,实际上是一个比较笨的办法. 网上查阅资料,发现google 提供了ddmlib库 (adt-bundle\ ...
- ASP.NET对HTML元素进行权限控制(一)
一个HTML页面有很多的元素比如<DIV>,<P>等.这些元素构成了HTML页面.在Web开发中权限控制是每个系统都要用到了.界面每个元素的权限也是需要控制的.比如一个查询用户 ...
- mysql查询差集
select A.* from A left join B using(name,addr,age) where B.name is NULL; select A.* from A left join ...
- nginx demo
server_names_hash_bucket_size 512;upstream node_app { server 127.0.0.1:3000; } server { listen 80; s ...