FZOJ Problem 2219 StarCraft
Accept: 226 Submit: 591
Time Limit: 1000 mSec Memory Limit : 32768
KB
Problem 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.
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).
Output
For each test case, output the answer of the question.
Sample Input
Sample Output
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.
题意:刀锋女王有了一个新技能,即可以使一只工蜂重新进入孵化期,卵经过k的时间会孵化出两只工蜂,现在有N个建筑要建造,每个建筑都有相应的建造时间,且每建造一个建筑需要牺牲工蜂,问最少需要多少时间完成建造。
思路:哈夫曼树+优先队列,建造时间越长的建筑需要尽量早点建造,在工蜂数量不足以同时建造所有建筑的时候,尽量先建造时间长的建筑,而建造时间短的建筑可以先进性孵化,用孵化后的工蜂来建造,这样贪心,将所有建筑的建造时间压入最小堆,每次选出建造时间最短的建筑出队列,对两者的建造时间进行一次合并,合并之后的时间=两者建造时间的最大值+一次孵化的时间k,再次将这个时间压入队列,直至队列中元素数量不大于工蜂数量为止,此时选出队列中最大的时间即可。
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
const int N_MAX = + ; int N, M,K;//N个建筑,M个农民,孵卵时间K
priority_queue<int,vector<int>,greater<int> >que;
int main() {
int T;
cin >> T;
while (T--) { scanf("%d%d%d",&N,&M,&K);
for (int i = ; i < N;i++) {
int t;
scanf("%d",&t);
que.push(t);
}
while (N>M) {//建筑多于农民时,每次合并建造时间最短的建筑
que.pop();
int t = que.top();
que.pop();
que.push(t + K);
N--;
}
while (que.size()>) {
que.pop();
}
cout << que.top() << endl;
que.pop();
}
return ;
}
FZOJ Problem 2219 StarCraft的更多相关文章
- FZU 2219 StarCraft(星际争霸)
Description 题目描述 ZB loves playing StarCraft and he likes Zerg most! One day, when ZB was playing SC2 ...
- FZOJ Problem 2150 Fire Game
...
- FZOJ Problem 2148 Moon Game
Proble ...
- FZOJ Problem 2107 Hua Rong Dao
...
- FZOJ Problem 2110 Star
...
- FZOJ Problem 2103 Bin & Jing in wonderland
...
- FZU-2219 StarCraft(贪心)
Problem 2219 StarCraft Accept: 294 Submit: 860Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- 【BZOJ】【2219】数论之神
中国剩余定理+原根+扩展欧几里得+BSGS 题解:http://blog.csdn.net/regina8023/article/details/44863519 新技能get√: LL Get_yu ...
- CSU 2018年12月月赛 G(2219): Coin
Description 有这样一个众所周知的问题: 你面前有7个硬币,其中有一个劣质的(它比正常的硬币轻一点点),你有一个天平,问需要你需要使用天平多少次能保证找到那个劣质的硬币. 众所周知的算法是: ...
随机推荐
- WPF DataGridCheckBoxColumn需要点两次才能修改checkbox状态
如题,如果必须要用DataGridCheckBoxColumn使用一下方式就可以解决需要点击两次才能改状态的问题 <DataGridCheckBoxColumn> <DataGrid ...
- python-IE浏览器调用
IE浏览器驱动添加 selenium官网有提供下载http://code.google.com/p/selenium/downloads/list 这里我用的是IEDriverServer_Win32 ...
- 01_12_JSP简介
01_12_JSP简介 1. JSP简介 JSP---Java Server Pages 拥有servlet的特性与优点(本身就是一个servlet) 直接在HTML中内嵌JSP代码 JSP程序有JS ...
- cocos2dx通过ndk编译c++库
ndk编译c++库,然后通过jni调用实现重要代码封装,是安卓应用中最常用的技术,一方面可以将重要的代码实现隐藏,防止泄漏,也可以提高打包速度. ndk里面的sample文件夹中有很多实用的例子,其中 ...
- new和delete的动态分配。
c++对象模型 视频的实际操作 note: 1.虚函数有虚指针,所以是4,不管有几个虚函数, 都只有一个vptr来存放调用的虚函数的地址. 2.子类的内存是父类内存的加自己的数据内存. 3.clas ...
- c++ 指针数组,输入4个季度的花费,计算出总花费
#include <iostream> #include <array> #include <string> const int Seasons = 4; cons ...
- Java--equals和 == 的比较和equals()、HashCode()的重写
一. equals和 == 的比较 1.== 运算符 ① == 如果比较的是基本数据类型,则比较的是值. ② == 如果比较的是引用数据类型,则比较的是地址值. 2.equals ①它属于java.l ...
- Linux-缓存服务
Memcached 基本操作 解释 命令 安装 yum install memcached 启动 memcached -d -l -m -p 停止 kill pid 查看某个端口是否通:telnet ...
- springBoot 集成swagger2.9.2
加依赖 <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui --> <dependen ...
- 阿里大鱼短信发送 FOR DT
//增加了参数$action 来标志发送的是什么短信 注册短信 验证码短信 提示短信等 function send_sms($mobile, $message, $word = 0, $time = ...