FZU-2219 StarCraft(贪心)
Problem 2219 StarCraftAccept: 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
3 1 1
1 3 5
5 2 2
1 1 1 1 10
Sample Output
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
第六届福建省大学生程序设计竞赛-重现赛(感谢承办方华侨大学)
#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(贪心)的更多相关文章
- FZU 2219 StarCraft(星际争霸)
Description 题目描述 ZB loves playing StarCraft and he likes Zerg most! One day, when ZB was playing SC2 ...
- FZU 2219【贪心】
思路: 因为工人造完一个房子就死了,所以如果m<n则还需要n-m个工人. 最优的方案应该是耗时长的房子应该尽快建,而且最优的是越多的房子在建越好,也就是如果当前人数不到n,只派一个人去分裂. 解 ...
- FZOJ Problem 2219 StarCraft
...
- FZU 2102 Solve equation(水,进制转化)&& FZU 2111(贪心,交换使数字最小)
C Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Pra ...
- FZU 2233 ~APTX4869 贪心+并查集
分析:http://blog.csdn.net/chenzhenyu123456/article/details/51308460 #include <cstdio> #include & ...
- FZU 2139——久违的月赛之二——————【贪心】
久违的月赛之二 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- 贪心 FZU 2013 A short problem
题目传送门 /* 题意:取长度不小于m的序列使得和最大 贪心:先来一个前缀和,只要长度不小于m,从m开始,更新起点k最小值和ans最大值 */ #include <cstdio> #inc ...
- FZU Problem 2221 RunningMan(贪心)
一开始就跑偏了,耽误了很长时间,我和队友都想到博弈上去了...我严重怀疑自己被前几个博弈题给洗脑了...贪心的做法其实就是我们分两种情况,因为A先出,所以B在第一组可以选择是赢或输,如果要输,那直接不 ...
- FZU 2144 Shooting Game(数学+贪心)
主要思路:求出蚊子到达球的时间区间(用方程得解),对区间做一个贪心的选择,选择尽可能多的区间有交集的区间段(结构体排序即可),然后计数. #include <cstdio> #includ ...
随机推荐
- Percona-Tookit工具包之pt-duplicate-key-checker
Preface I suppose that we have a requirement of checking out how many duplicated indexes on ...
- Appium与python自动测试环境及demo详解
App--UI自动化这种高端的名词已经被越来越多的人所高呼,可是从实际角度来讲,个人觉得还是有点鸡肋,不如接口自动化敏捷度高,工作量 也是接口自动化的好几倍.但是,[划重点了] 在技术时代中,作为测 ...
- python学习总结---文件操作
# 文件操作 ### 目录管理(os) - 示例 ```python # 执行系统命令 # 清屏 # os.system('cls') # 调出计算器 # os.system('calc') # 查看 ...
- 孤荷凌寒自学python第五十天第一次接触NoSql数据库_Firebase
孤荷凌寒自学python第五十天第一次接触NoSql数据库_Firebase (完整学习过程屏幕记录视频地址在文末) 之前对关系型数据库的学习告一段落,虽然能力所限没有能够完全完成理想中的所有数据库操 ...
- centos 7 安装codeblocks
CentOS7安装Code::Blocks 在CentOS7上安装Codelocks的过程. 1.安装gcc,需要c和c++两部分,默认安装下,CentOS不安装编译器的,在终端输入以下命令即可yum ...
- NodeJs06 高并发
高并发架构 在业务的最初期,由于业务和用户的体量比较小,可能采用单机就足够了.随着业务的增长,用户量和并发请求量都会不断上升.当增长到一定的瓶颈的时候,系统能否抗住压力,就需要采取一些方案了.这就是著 ...
- STL之map&multimap使用简介
map 1.insert 第一种:用insert函数插入pair数据 #include <map> #include <string> #include <iostrea ...
- Java对字符串进行加密
package anli1; import java.util.Scanner; public class example { public static void main(String[]args ...
- over窗口函数进阶
over窗口函数的其他灵活的用法.即,统计当前行的前N行及后N行数据.转自:https://blog.csdn.net/ck3207/article/details/84954511 先来看一下数据的 ...
- tcp slowstart (TCP 慢启动)
tcp slowstart (TCP 慢启动) 慢启动定义 慢启动,是传输控制协议使用的一种拥塞控制机制.慢启动也叫做指数增长期.慢启动是指每次TCP接收窗口收到确认时都会增长.增加的大小就是已确认段 ...