1620. SCVs and minerals
Constraints
Time Limit: 1 secs, Memory Limit: 64 MB
Description
When you are playing the game call “StarCraft”, if you choose “Terran”, you will have some SCVs, some minerals, and a command center. The SCVs can collect minerals outside and put them into the command center, and you can let the command center produce SCV by minerals. You want to win the game, so you must use the SCVs to collect more minerals.
Initially you have N SCVs and M minerals. Every SCV can get C minerals in one second, and the command center can produce SCVs immediately by P minerals. You want to maximize the minerals you have after S seconds. Please calculate it.
Input
The first line of the input is a positive integer T (1<=T<=50). T is the number of test cases followed. Each test case contains 5 integers, N, M, C, P, S. (1<=N<=10, 0<=M<=100, 1<=C<=10, 50<=P<=100, 1<=S<=50)
Output
For each test case, output the maximum number of minerals you have after S seconds, in one line.
Sample Input
3
10 3 10 50 2
10 0 10 60 10
4 50 8 50 50
Sample Output
203
1090
149512
(~ ̄▽ ̄)~ 简单贪心算法,解题关键在于判断是否需要建造SCVs。怎样判定?很简单,只要建造该SCVs能够在剩下的时间收回成本即可。
#include <iostream>
using namespace std;
int main()
{
int T, N, M, C, P, S;
cin >> T;
while (T--)
{
cin >> N >> M >> C
>> P >> S;
do
{
if (M >= P && C * S >= P)
{
N += M / P;
M %= P;
}
M += N * C;
} while (--S);
cout << M << endl;
}
return 0;
}