FZU 2219 StarCraft
2018-01-28 17:11
351 查看
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
(1 <= t[i] <= 100000).
Output
For each test case, output the answer of the question.
Sample Input
Sample Output
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.
#include<cstdio>
#include<queue>
#include<functional>
std::priority_queue<int, std::vector<int>, std::greater<int> > data;
int main(){
int t, N, M, K, i, j;
scanf("%d", &t);
while (t--){
scanf("%d%d%d", &N, &M, &K);
for (i = 0; i < N; ++i) scanf("%d", &j), data.push(j);
while (N > M){
data.pop();
data.push(data.top() + K);
data.pop();
--N;
}
while (data.size() != 1) data.pop();
printf("%d\n", data.top());
data.pop();
}
return 0;
}
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
(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.
#include<cstdio>
#include<queue>
#include<functional>
std::priority_queue<int, std::vector<int>, std::greater<int> > data;
int main(){
int t, N, M, K, i, j;
scanf("%d", &t);
while (t--){
scanf("%d%d%d", &N, &M, &K);
for (i = 0; i < N; ++i) scanf("%d", &j), data.push(j);
while (N > M){
data.pop();
data.push(data.top() + K);
data.pop();
--N;
}
while (data.size() != 1) data.pop();
printf("%d\n", data.top());
data.pop();
}
return 0;
}
相关文章推荐
- FZU - 2219 StarCraft (哈夫曼树,贪心+优先队列)
- FZU 2219 StarCraft(贪心+优先队列)
- FZU2219 StarCraft(哈夫曼树)
- FZU 2219 StarCraft (贪心 优先队列)
- FZU 2219 StarCraft (哈夫曼树)
- FZU 2219 StarCraft(优先队列贪心)
- FZU - 2219 StarCraft
- FZU2219 StarCraft--贪心+优先队列
- FZOJ Problem 2219 StarCraft
- FZU 2219【贪心】
- fzu 2219 Huffman应用(贪心+优先队列)
- FZU1894 志愿者选拔 --单调队列
- FZU 1753 Another Easy Problem 解题报告(素因子统计)
- fzu 2171 防守阵地 II
- fzu 2087并查集的运用求最小生成树的等效边
- Fzu 2113 Jason的特殊爱好 (数位dp)
- FZU 2165 Climb Stairs(DP)
- fzu 1921
- FZU 2147 A-B Game
- FZU 2020 组合(Lucas定理的应用)