Cosmocrafttime limit: 1000 msmemory limit: 32768 kbthis problem will be judged on HDU. Original ID: 4257
64-bit integer Io format: % i64d Java class name: main in the two-player game cosmocraft you manage an economy in the hopes of producing an army capable of defeating your opponent. you manage the construction of workers, production facilities, and army units; the game revolves around balancing the resources you allocate to each. the game progresses in turns.
1.Workers give you income at the rate of 1 dollar per turn.
2.Production facilities let you produce either an army unit or a worker for the cost of 1 dollar. (Only 1 army unit or worker can be produced per turn per facility)
3.It costs 1 dollar to create a production facility.
4.Your army, of course, lets you fight against your opponent.
You start off with N workers and K production facilities. the game progresses in turns-at each turn, you can spend the income you get from your workers on a mixture of workers, army, and creating production facilities. workers produced this round do not give you income until the next round; likewise, production facilities do not become active until the next round. any unspent income from the current round carries over to the next.
At the end of a round, you can take the total army you 've produced and attack your opponent; if you have strictly more units than your opponent, the opponent loses immediately, and you retain the difference of the Army sizes. otherwise, your army is crushed and your opponent is left with the difference of the Army sizes. (It wocould be wise for him to counter-attack after this, but you don't lose immediately at least ). the game ends after T turns, at which point both players will usually attack with the larger army reigning various IOUs.
You're playing against your friend, and since you 've ve played against him so many times you know exactly what he's going to spend his money on at every turn, and exactly when he's going to attack. knowing this, you 've decided that the best strategy is to play defensively-you just want to keep ve every attack, and amass as large an army in the meantime so you can counterattack (and hopefully win) at the end of the game.
What's the largest army you can have at the end of the game, given that you must keep ve all your friend's attacks? Inputthere will be several test cases in the input. Each test case will begin with a line with three integers:
N K T
Where n (1 ≤
N≤ 100) is the number of workers you start,
K(1 ≤
K≤ 100) is the number of production facilities you have at the start, and
T(1 ≤
T≤ 10,000) is the number of turns. On the next line will be
T-1 integers,
AI (0 ≤
AI ≤ Max signed 64-bit integer), separated by single spaces. the ith integer indicates the strength of the attack (that is, the number of army units your opponent is using in that attack) on turn I. the input will end with a line with three 0 s.
Hint
Huge input, please ues C ++. outputfor each test case output a single integer indicating the maximum number of armies you coshould have at the end of the game. output-1 if it is impossible to keep ve. output each integer on its own line, with no spaces, and do not print any blank lines between answers. while it is possible for some inputs to generate unreasonably large answers, all judge inputs yield answers which will fit in a signed 64-bit integer. sample Input
8 4 622 6 10 14 04 3 30 06 9 70 0 11 0 7 00 0 0
Sample output
-111101
Sourcethe University of Chicago Invitational Programming Contest 2012 problem solving: Turn from others
Theme
This article introduces a two-person turn-based strategy game called cosmocraft (but this game cannot be found online). Players in each round can: 1. 1 RMB/buyer, 2. 1 RMB/soldier, 3. 1 RMB/device for barracks. One worker can earn 1 yuan per round, but the money will be given to you in the next round. Each barracks can only create one worker or soldier per round, barracks constructed in the same round will be available in the next round, and workers or soldiers created in each round will be available in the current round. The game initially gave you n workers and K barracks and N yuan, game t round, the previous T-1 round each round will have a [I] enemy soldiers back to attack you, you must be able to withstand each round of attack, that is, each round has more soldiers than your enemy army, and each war has more soldiers to win, there is no difference between the number of soldiers on both sides of the battle, but the number of soldiers on the failed side is no longer left. Please use the best strategy to make the most soldiers in the round t counterattack, and output the maximum value.
Greedy policy:
1. All the money is required for each round.
2. A soldier cannot have more than two rounds in a row (if there are no battles in more than two rounds, he can spend 1 RMB to create a barracks in the first round and with the money earned by the worker in the second round, in the third round, we will use the money earned by the workers and the soldiers to create soldiers ).
3. On the premise of ensuring the survival of each round, create as many workers as possible, how much can be made, and the remaining money to recreate the barracks.
4. According to Rule 2, soldiers of round I (1 <= I <= T) can only be created by round I or I-1, if d [I] soldiers can be created in round I, they will be created in round I; otherwise, support from round I-1 will be needed, the I-1 Round supports up to K [I-1]-U [I-1] soldiers (in the case of W [I-1]> K [I-1) otherwise, it cannot defend against round I attacks. (K [I] indicates the number of barracks in the I round, N [I] indicates the number of engineers in the I round, and U [I] indicates the number of soldiers required in the I round ).
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 # include <algorithm> 6 # include <climits> 7 # include <vector> 8 # include <queue> 9 # include <cstdlib> 10 # include <string> 11 # include <set> 12 # include <stack> 13 # define ll long long14 # define PII pair <int, int> 15 # define INF 0x3f3f3f16 using namespace STD; 17 const int maxn = 100100; 18 ll d [maxn], n, k, T, U, themin; 19 in T Main () {20 int I, j; 21 bool flag; 22 while (scanf ("% i64d % i64d % i64d", & N, & K, & T ), N | K | T) {23 for (I = 1; I <t; I ++) scanf ("% i64d", D + I ); 24 d [T] = 0; 25 if (min (n, k) <D [1]) {puts ("-1"); continue ;} 26 U = d [1]; 27 flag = false; 28 for (I = 1; I <t; I ++) {29 If (n + min (n, k) -U <D [I + 1]) {flag = true; break;} // use the last remaining 30 // to create some themin = min (n, k); // 32 K + = N-themin; // when N> K, 33 N + = Themin-U; // create a themin user, then go to war, die some, and then the remaining 34 if (d [I + 1]> K) {// 35 N-= d [I + 1]-K is not enough for the next round of attacking military camp; // use some workers to replace d [I + 1]-k people, 36 U = K; // There are so many dead, and K dead are required. 37} else u = d [I + 1]; 38} 39 if (FLAG) {puts ("-1"); continue;} 40 if (t = 1) printf ("% i64d \ n", u <k? U: K); 41 else printf ("% i64d \ n", n); 42} 43 return 0; 44}
View code