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. Hyper-V 安装Windows 2008,08 R2,12 R2 无网卡驱动的解决办法

    最近玩 Hyper -V ,都是在网上找的资料进行操作的.后面发觉园友提供的一些操作 按部就班的做下来,别人 可以 ,我的就是不行. 最近就遇到一个很烦闷的事情.(如题) 安装好系统之后 发现 没有网 ...

  2. selenium定位弹出菜单

    写selenium脚本,在浏览器定位各种弹出菜单时,有时用工具很难去取菜单的属性,下面说下如何去取: 点开firebug ,切换到“脚本”界面,首先在输入框输入单字母s,待弹出下拉列表后,单击左侧的插 ...

  3. Python之日志处理 logging模块

    Python之日志处理(logging模块)   本节内容 日志相关概念 logging模块简介 使用logging提供的模块级别的函数记录日志 logging模块日志流处理流程 使用logging四 ...

  4. cloud.cfg_for_centos

    users: - default disable_root: 0 ssh_pwauth: 1 locale_configfile: /etc/sysconfig/i18n mount_default_ ...

  5. c++知识点总结-模板特化

    类模板的全特化与偏特化 类模板 template<typename T1, typename T2> class Test { public: Test(T1 i,T2 j):a(i),b ...

  6. django orm 之makemigrations和migrate命令

    makemigrations:将模型的更改生成迁移脚本文件.模型所在的app,必须放在settings.py中的INSTALLED_APPS列表中.这个命令有以下几个常用选项: 1.app_label ...

  7. 通过nbviwer在线分享python notebook

    在数据科学计算中,jupyter-notebook是一个很得力的助手,但是Notebook写完之后如何与他人分享呢?我们可以使用nbviwer. 具体思路: 具体的方法如下: 本地编写ipython ...

  8. B - Help Jimmy

    B - Help Jimmy Time Limit: 1000/1000MS (C++/Others) Memory Limit: 65536/65536KB (C++/Others) Problem ...

  9. 【ZBH选讲·树变环】

    [问题描述] 你是能看到第三题的friends呢.——aoao 树是个好东西,删掉树一条边要1的代价,随便再加一条边有1的代价,求最小的代价把树变成环.[输入格式] 第一行一个整数,代表树的点数.接下 ...

  10. Extra Judicial Operation

    Description The Suitably Protected Programming Contest (SPPC) is a multi-site contest in which conte ...