FZU-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
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 ...
随机推荐
- Python 基础学习篇
注:技术尚浅,时间匆忙,如有错误或者不当之处值得商榷的,请留言,吾必思而改之. 第一篇 :Python基础- 安装/变量/输入/及循环语句使用 第二篇: Python基础- 常用数据类型 第三篇: ...
- unity灯光Lightmapping、LightProbes
1.为什么要用Lightmapping? 简单来说就是实时灯光计算十分耗时,随着光源越多,计算耗时会倍增.使用Lightmap模拟灯光带来的效果,便不用去计算灯光,会带来性能上的大大提升. 当然一个复 ...
- Linux 文本对比 diff 命令详解(整理)
diff 命令详解 1.概述 windows系统下面就有不错的文本对比工具可以使用,例如常用的Beyond Compare,WinMerge都是图形界面的比较工具而且使用非常方便,如果你仅仅是在win ...
- HDU 4655 Cut Pieces 找规律+简单计数
解法参考:http://blog.csdn.net/a601025382s/article/details/9840125 #include <cstdio> #include <c ...
- Android可移动的Button
关键 package com.example.administrator.mystudent.ButtonMove; import android.app.Activity; import andro ...
- android ViewGroup getChildDrawingOrder与 isChildrenDrawingOrderEnabled()
getChildDrawingOrder与 isChildrenDrawingOrderEnabled()是属于ViewGroup的方法. getChildDrawingOrder 用于 返回当前 ...
- web自动化测试:watir+minitest(五)
测试报告: 加载minitest-reporters库,并设置相关的参数.既可以在每次运行测试后生成响应的测试报告. 默认会生成一份html的报告在当前目录的test目录下 我们可以指定参数对报告的标 ...
- cfq调度器
cfq调度是block层最复杂的一个调度器,主要思想是是说每个进程平均享用IO带宽,实现方法是在时间上对进程进行划分,以此达到平均占用IO的目的.带着几个问题去看cfq 1)现在进程来了之后,是插入到 ...
- 网站前后台分离 图片 flash 视频 等文件的共享问题
在网上找了,没有说到点子上的,不详细 问了有经验的同事,要建立 文件服务器,就是一个IIS 下的新网站,网站是共享图片 文件使用的专用网站 后台上传的图片保存在 文件服务器即 文件共享专用的网站目录地 ...
- OpenNI2安装
1.Openni2:从官网下载linux用zip压缩包,解压再解压2.终端转到解压目录下,找到install.sh文件,执行$sudo ./install.sh 3.执行后,生成OpenNIDevEn ...