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个硬币,其中有一个劣质的(它比正常的硬币轻一点点),你有一个天平,问需要你需要使用天平多少次能保证找到那个劣质的硬币. 众所周知的算法是: ...
随机推荐
- DROP GROUP - 删除一个用户组
SYNOPSIS DROP GROUP name DESCRIPTION 描述 DROP GROUP 从数据库中删除指定的组.组中的用户不被删除. 组中的用户不被删除. PARAMETERS 参数 n ...
- Ping 命令的执行过程和应用协议
1. ICMP是“Internet Control Message Ptotocol”的缩写.它是TCP/IP协议族的一个子协议,用于在IP主机.路由器之间传递控制消息. 控制消息是指网络通不通.主机 ...
- 如何使用postman做接口测试
1.get请求传参 只要是get请求都可以在浏览器中直接发: 在访问地址后面拼 ?key=value&key=value 例如: 在浏览器中直接输入访问地址,后面直接拼需要传给服务器的参数 ...
- German Collegiate Programming Contest 2018 B. Battle Royale
Battle Royale games are the current trend in video games and Gamers Concealed Punching Circles (GCPC ...
- poj 2676 数独问题 dfs
题意:完成数独程序,数独要求每行每列且每个3*3矩阵都必须是1~9的数字组成. 思路:dfs 用row[i][n] 记录第i行n存在 用col[j][n] 记录第j列n存在 grid[k][n] 记 ...
- 【转】MySQL innodb_autoinc_lock_mode 详解 ,并发插入时主键冲突的解决方案
本文转载于 http://www.cnblogs.com/JiangLe/p/6362770.html innodb_autoinc_lock_mode这个参数控制着在向有auto_increment ...
- Angular Vue React 框架中的 CSS
框架中的 CSS Angular Vue React 三大框架 Angular Vue 内置样式集成 React 一些业界实践 Angular Angular . js (1.x):没有样式集成能力 ...
- 精通 JavaScript中的正则表达式
精通 JS正则表达式 (精通?标题党 ) 正则表达式可以: •测试字符串的某个模式.例如,可以对一个输入字符串进行测试,看在该字符串是否存在一个电话号码模式或一个信用卡号码模式.这称为数据有效性验证 ...
- luogu2114 [NOI2014]起床困难综合症
大约是第一次做近几年NOI题(尽管是签到题)? 制作一个真值表,要是有哪一位原本是0但是能变成1那真是太好啦,要是有哪一位原来是1能变成1并且算上它不会超过m那也不错. #include <io ...
- ogre3d环境配置与简单程序示例
SDK安装以及编译 1.下载SDK,地址如下 http://www.ogre3d.org/download/sdk 2.安装SDK,直接解压到相应目录,如D:/ogreSDK 3.我用的是1.8版本, ...