FZU 2219 StarCraft(星际争霸)
Description |
题目描述 |
ZB loves playing StarCraft and he likes Zerg most! One day, when ZB was playing SC2, he came up with an idea: He wants to change the queen's ability, the queen's new ability is to choose a worker at any time, and turn it into an egg, after K units of time, two workers will born from that egg. The ability is not consumed, which means you can use it any time without cooling down. Now ZB wants to build N buildings, he has M workers initially, the i-th building costs t[i] units of time, and a worker will die after he builds a building. Now ZB wants to know the minimum time to build all N buildings. |
ZB喜欢玩星际争霸并且他爱用虫族! 有一天,在ZB玩星际争霸2的时候,脑洞乍开: 他想改变女王的技能,女王的新技能可以在任何时候指定一只农民,使其变成一个虫卵,K个单位时间后,两只农民将被孵化出来。此技能没有消耗,意味着你不需要担心冷却时间。 ZB想建N个建筑,他有M个初始农民,第i个建筑需要t[i]个单位时间,并且农民在完成建筑后立即死亡。现在ZB想知道建完全部N个建筑的最短时间。 |
Input |
输入 |
The first line contains an integer T, meaning the number of the cases. 1 <= T <= 50. For each test case, the first line consists of three integers N, M and K. (1 <= N, M <= 100000, 1 <= K <= 100000). The second line contains N integers t[1] ... t[N](1 <= t[i] <= 100000). |
输入的首行是一个整数T,表示测试样例的数量。1 <= T <= 50。 对于每个测试样例,第一行有3个整数N,M和K。(1 <= N, M <= 100000, 1 <= K <= 100000)。 第二行有N个整数t[1] ... t[N](1 <= t[i] <= 100000)。 |
Output |
输出 |
For each test case, output the answer of the question. |
对于每个测试样例,输出问题的答案。 |
Sample Input - 输入样例 |
Sample Output - 输出样例 |
2 3 1 1 1 3 5 5 2 2 1 1 1 1 10 |
6 10 |
Hint |
提示 |
For the first example, turn the first worker into an egg at time 0, at time 1 there’s two worker. And use one of them to build the third building, turn the other one into an egg, at time 2, you have 2 workers and a worker building the third building. Use two workers build the first and the second building, they are built at time 3, 5, 6 respectively. |
对于第一个例子,在0时刻选择农民变虫卵,在1时刻有2个农民。然后用一个去建第三个建筑,另一个变成虫卵。 在2时刻,你有2个农民,并且第三个建筑正在建造。用两个农民分别建造第一和第二个建筑,他们会在时刻3,5,6分别完成。 |
【题解】
类似哈夫曼树的合并方式,对于当个农民(工蜂)来说,算上分裂技能,建造是不断两两并行的,建造时间越小,合并的价值就越小。合并后的时间去被合并两者的较大值+K。初始农民的数量就是合并的终点。
然后问题可以化成,给你一堆数字,每次把次小值+K,再删除当前最小值,直到剩下M个数字。
【代码 C++】
multiset会超时,还是用优先队列吧,默认排序的大根堆,改成小根堆就好了。
代码只是为了简洁与能过,想要理想的效率还是要经过进一步的优化。
#include<cstdio>
#include<queue>
#include<functional>
std::priority_queue<int, std::vector<int>, std::greater<int> > data;
int main(){
int t, N, M, K, i, j;
scanf("%d", &t);
while (t--){
scanf("%d%d%d", &N, &M, &K);
for (i = ; i < N; ++i) scanf("%d", &j), data.push(j);
while (N > M){
data.pop();
data.push(data.top() + K);
data.pop();
--N;
}
while (data.size() != ) data.pop();
printf("%d\n", data.top());
data.pop();
}
return ;
}
FZU 2219
FZU 2219 StarCraft(星际争霸)的更多相关文章
- PySC2是DeepMind的“星际争霸II学习环境”(SC2LE)的Python组件
PySC2是DeepMind的"星际争霸II学习环境"(SC2LE)的Python组件. 它暴露了暴雪娱乐公司的星际争霸II机器学习API作为Python RL环境. 这是Deep ...
- 2018年星际争霸AI挑战赛–三星与FB获冠亚军,中科院自动化所夺得季军
雷锋网 AI 科技评论消息,2018 年 11 月 13-17 日,AAAI 人工智能与交互式数字娱乐大会 (AI for Interactive Digital Entertainment) 在阿尔 ...
- 星际争霸2 AI开发(持续更新)
准备 我的环境是python3.6,sc2包0.11.1 机器学习包下载链接:pysc2 地图下载链接maps pysc2是DeepMind开发的星际争霸Ⅱ学习环境. 它是封装星际争霸Ⅱ机器学习API ...
- FaceBook 发布星际争霸最大 AI 数据集
简介 我们刚发布了最大的星际争霸:Brood War 重播数据集,有 65646 个游戏.完整的数据集经过压缩之后有 365 GB,1535 million 帧,和 496 million 操作动作. ...
- 20. 星际争霸之php设计模式--适配器模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
- 19. 星际争霸之php设计模式--迭代器模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
- 18. 星际争霸之php设计模式--观察者模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
- 17. 星际争霸之php设计模式--职责链模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
- 16. 星际争霸之php设计模式--组合模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
随机推荐
- U盘启动引导安装linux
一.U盘引导,安装前的准备 1.U盘一枚,至少2G 2.下载并安装虚拟光驱,这里我用的是UltralSO. 二.制作引导盘 1.打开UltraISO软件,选择文件->打开,打开需要烧录的镜像文件 ...
- Mac下好用的取色器 Sip
总有很多东西,你只是望一眼就已经神魂颠倒.措施有这样的App做的真的是用心的很,养眼,触发你内心冲动的美感.先留下一个,备忘. 太精致了 操作简单,左上角的有心圆点击就可以在任何地方取色了,取色点会z ...
- Mac OX 隐藏文件夹,文件,应用,磁盘的2种方法 hide finder folder, file, application, volume in 2 ways
经常需要主目录下隐藏一些文件夹之类的, 第一想到的当然就是:在要隐藏的文件夹前面加『.』(leading dot),这个用法当然可以的了 用习惯了Linux/GNU系统的,基本习惯使用这种办法 但是, ...
- MyBatis的Dao层注入SqlSession
有点坑爹,以前没用过Mybatis,最近才用,而且一直用Mybatis推荐的接口映射的方式,但是今天有人告诉我接口方式用得少,大多还是采用从配置文件里面读sql的方式,当然接口也是类似的,都是利用ma ...
- Best Time to Buy and Sell Stock
class Solution { public: int maxProfit(vector<int>& prices) { //eg: 5 6 2 3 1 4: // 记录i之前最 ...
- MySQL start and stop
一.本文说明 本实验主要是演示MySQL的四种启动方式,附带停止的操作. 二.mysqld mysqld is the MySQL server mysqld reads options from ...
- freeMarker中list的两列展示
前台界面中我使用freeMarker的机会有很多,自然也就会接触下<List>标签,我想大家应该都不陌生.<#list attrList as attr>${a.name}&l ...
- HttpClient的使用方法
使用httpClient发送请求.接收响应很简单.一般需要以下几个步骤. 第一:创建HttpClient对象: 第二:创建请求方法的实例,并指定请求URL.如果要发送GET请求,创建HttpGet对象 ...
- JQuery-遮罩层
HTML <html> <head> <link href="StyleSheet.css" rel="stylesheet" t ...
- 周赛-Toy Cars 分类: 比赛 2015-08-08 15:41 5人阅读 评论(0) 收藏
Toy Cars time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...