Problem 2219 StarCraft

Accept: 294    Submit: 860
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.

 Source

第六届福建省大学生程序设计竞赛-重现赛(感谢承办方华侨大学)

题意:起始有m个农民,要建N个建筑,建第i个建筑要用t[i]个时间,不过可以指定一个农民变成蛋在K时间后变成两个农民,每次农民只能建立一个建筑
思路:每次把需要消耗最少时间建筑的农民分裂,保证时间最充分利用
代码“

#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#define INF 0x3f3f3f3f
using namespace std;
struct node{
int time;
bool operator <(const node &a)const{
return time>a.time;
}
}; int main(){
int t;
std::ios::sync_with_stdio(false);
cin>>t;
while(t--){
int n,m,k;
priority_queue<node>pq;
node a;
cin>>n>>m>>k;
for(int i=0;i<n;i++){
cin>>a.time;
pq.push(a);
}
while(n>m){
pq.pop();
node a=pq.top();
a.time+=k;
pq.push(a);
pq.pop();
n--;
}
while(pq.size()!=1)pq.pop();
cout<<pq.top().time<<endl;
}
return 0;
}

  

FZU-2219 StarCraft(贪心)的更多相关文章

  1. FZU 2219 StarCraft(星际争霸)

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

  2. FZU 2219【贪心】

    思路: 因为工人造完一个房子就死了,所以如果m<n则还需要n-m个工人. 最优的方案应该是耗时长的房子应该尽快建,而且最优的是越多的房子在建越好,也就是如果当前人数不到n,只派一个人去分裂. 解 ...

  3. FZOJ Problem 2219 StarCraft

                                                                                                        ...

  4. FZU 2102 Solve equation(水,进制转化)&& FZU 2111(贪心,交换使数字最小)

    C Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Pra ...

  5. FZU 2233 ~APTX4869 贪心+并查集

    分析:http://blog.csdn.net/chenzhenyu123456/article/details/51308460 #include <cstdio> #include & ...

  6. FZU 2139——久违的月赛之二——————【贪心】

    久违的月赛之二 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  7. 贪心 FZU 2013 A short problem

    题目传送门 /* 题意:取长度不小于m的序列使得和最大 贪心:先来一个前缀和,只要长度不小于m,从m开始,更新起点k最小值和ans最大值 */ #include <cstdio> #inc ...

  8. FZU Problem 2221 RunningMan(贪心)

    一开始就跑偏了,耽误了很长时间,我和队友都想到博弈上去了...我严重怀疑自己被前几个博弈题给洗脑了...贪心的做法其实就是我们分两种情况,因为A先出,所以B在第一组可以选择是赢或输,如果要输,那直接不 ...

  9. FZU 2144 Shooting Game(数学+贪心)

    主要思路:求出蚊子到达球的时间区间(用方程得解),对区间做一个贪心的选择,选择尽可能多的区间有交集的区间段(结构体排序即可),然后计数. #include <cstdio> #includ ...

随机推荐

  1. 【APUE】Chapter7 Process Environment

    这一章内容是Process的基础准备篇章.这一章的内容都是基于C Programm为例子. (一)进程开始: kernel → C start-up rountine → main function ...

  2. C#泛型和泛型约束

    一.泛型: 所谓泛型,即通过参数化类型来实现在同一份代码上操作多种数据类型.泛型编程是一种编程范式,它利用“参数化类型”将类型抽象化,从而实现更为灵活的复用. 二.泛型约束: 转自:http://ww ...

  3. 数据分析—NaN数据处理

    目的 1.查找NaN值(定位到哪一列.在列的哪个索引位置) 2.填充NaN值(向上填充.向下填充.线性填充等) 3.过滤NaN值 构建简单的Dataframe数据结构环境 import pandas ...

  4. Python编码报错

    Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法在编写Python时,当使用中文输出或注释时运行脚本,会提示错误信息:SyntaxErr ...

  5. HDU 4057 Rescue the Rabbit ( AC自动机 + 状态压缩DP )

    模板来自notonlysuccess. 模式串只有10个,并且重复出现的分值不累加,因此很容易想到状态压缩. 将模式串加入AC自动机,最多有10*100个状态. dp[i][j][k]:串长为i,在T ...

  6. UVALive 6324 Archery (求射箭覆盖的期望)

    #include<cstdio> #include<cmath> #include<cstring> #include<cstdlib> const d ...

  7. Thread 线程池

    Thread 线程池: 当使用多个较短存活期的线程有利时,运用线程池技术可以发挥作用.运用这一技术时,不是为每个任务创建一个全新的线程,而可以从线程池中抽出线程,并分配给任务.当线程完成任务后,再把它 ...

  8. DOM关于高度宽度位置的获取

    假设 obj 为某个 HTML 控件. obj.offsetTop 指 obj 相对于版面或由 offsetParent 属性指定的父坐标的计算上侧位置,整型,单位像素. obj.offsetLeft ...

  9. (总结)Linux下查看Nginx Apache MySQL的并发连接数和连接状态

    1.查看Web服务器(Nginx Apache)的并发请求数及其TCP连接状态:netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a ...

  10. Nginx 战斗准备 —— 优化指南

    大多数的Nginx安装指南告诉你如下基础知识——通过apt-get安装,修改这里或那里的几行配置,好了,你已经有了一个Web服务器了!而且,在大多数情况下,一个常规安装的nginx对你的网站来说已经能 ...