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

2 3 1 1 1 3 5 5 2 2 1 1 1 1 10

Sample Output

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.

题意:刀锋女王有了一个新技能,即可以使一只工蜂重新进入孵化期,卵经过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的更多相关文章

  1. FZU 2219 StarCraft(星际争霸)

    Description 题目描述 ZB loves playing StarCraft and he likes Zerg most! One day, when ZB was playing SC2 ...

  2. FZOJ Problem 2150 Fire Game

                                                                                                        ...

  3. FZOJ Problem 2148 Moon Game

                                                                                                  Proble ...

  4. FZOJ Problem 2107 Hua Rong Dao

                                                                                                        ...

  5. FZOJ Problem 2110 Star

                                                                                                        ...

  6. FZOJ Problem 2103 Bin & Jing in wonderland

                                                                                                        ...

  7. FZU-2219 StarCraft(贪心)

     Problem 2219 StarCraft Accept: 294    Submit: 860Time Limit: 1000 mSec    Memory Limit : 32768 KB   ...

  8. 【BZOJ】【2219】数论之神

    中国剩余定理+原根+扩展欧几里得+BSGS 题解:http://blog.csdn.net/regina8023/article/details/44863519 新技能get√: LL Get_yu ...

  9. CSU 2018年12月月赛 G(2219): Coin

    Description 有这样一个众所周知的问题: 你面前有7个硬币,其中有一个劣质的(它比正常的硬币轻一点点),你有一个天平,问需要你需要使用天平多少次能保证找到那个劣质的硬币. 众所周知的算法是: ...

随机推荐

  1. Luogu P1666 前缀单词

    校内资格赛题目,差点高一就要\(\tt{AFO}\)了 30分思路 对30%的数据,满足$1≤n≤10 $ 所以我们可以子集枚举,实际得分40pts #include<iostream> ...

  2. MySQL的GTID复制与传统复制的相互切换

    MySQL的GTID复制与传统复制的相互转换 1. GTID复制转换成传统复制 1.1 环境准备 1.2 停止slave 1.3 查看当前主从状态 1.4 change master 1.5 启动主从 ...

  3. Linux常用快捷键以及如何查看命令帮助

    1.1    Linux系统快速操作常用快捷键 快捷键名称 快捷作用 Ctrl + a 将光标移至行首 Ctrl + e 将光标移至行尾 Ctrl + u 前提光标在行尾,则清除当前行所有的内容(有空 ...

  4. 五一4天就背这些Python面试题了,Python面试题No12

    第1题: Python 中的 os 模块常见方法? os 属于 python内置模块,所以细节在官网有详细的说明,本道面试题考察的是基础能力了,所以把你知道的都告诉面试官吧 官网地址 https:// ...

  5. centos新增或删除用户

    新增用户snzigod:adduser snzigod 修改snzigod密码:passwd snzigod 删除用户snzigod:userdel snzigod 删除用户以及用户目录: userd ...

  6. debian 升级glibc

    原因 wheezy是2.13,编译android4.4 需要2.14的,报错如下: rebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8-linar ...

  7. SQL_4_函数

    在SQL的函数中可以执行一些诸如对某一些进行汇总或将一个字符串中的字符转换为大写的操作等: 函数有:汇总函数.日期与时间函数.数学函数.字符函数.转换函数与其他函数. 汇总函数 这是一组函数,它们返回 ...

  8. selenium2截图ScreenShot的使用

    截图是做测试的基本技能,在有BUG的地方,截个图,保留失败的证据,也方便去重现BUG.所以,在自动化的过程中,也要能截图,也要能在我们想要截取的地方去截图,且能在错误产生时,自动的截图. 示例: 脚本 ...

  9. 中国首届CSS开发者大会讲师照片

    中国首届CSS开发者大会讲师照片 Bert Bos Winter 点头猪 灭灭 jaychsu Hax 尤雨溪 一丝 勾三股四 小倩 **

  10. Java学习笔记1---JVM、JRE、JDK

    jdk包含jre,jre包含jvm. 用java语言进行开发时,必须先装jdk: 只运行java程序,不进行开发时,可以只装jre. JVM 即Java Virtual machine,Java虚拟机 ...