
1998 HIGH SCHOOL PROGRAMMING CONTEST
Problem 4 – Global Thermonuclear Warfare
Description:
A certain little computer geek has managed to crack into NORAD and has begun to run a simulation of a global thermonuclear conflict. Your job is to write that simulator. The conflict involves five nations (Russia, China, England, France and the US), each with an unlimited arsenal of nuclear missiles. Each country has a set sequence of targets that it fires upon. Each country also has a fixed strength value, which contains the number of hits it can withstand. The user must enter the number of missiles that each country can fire per volley (turn).
The simulator operates as a turn-based system. At the beginning of each turn, all countries simultaneously fire all the missiles allocated to them for that turn. Targets for the individual missiles are chosen in sequence from the firing country’s target list. Every missile hits its target, and causes one hit point worth of damage. After all the missiles have been fired for the turn, those countries whose damage points drop to zero are declared dead. Dead countries cannot fire any more missiles (duh) and are no longer targeted by the remaining “live” countries.
The following table details the firing sequence of each of the countries, as well as their total strength rating. (and no, France’s targets are not a typo… their nuclear engineers were too busy watching Jerry Lewis movies to properly aim their missiles)
|
Name |
1st Target |
2nd Target |
3rd Target |
4th Target |
Strength |
|
United States |
France |
Russia |
China |
China |
100 |
|
Russia |
United States |
France |
England |
United States |
90 |
|
China |
Russia |
United States |
England |
United States |
110 |
|
England |
China |
France |
France |
Russia |
50 |
|
France |
France |
England |
Russia |
China |
70 |
A partial example of
a turn execution:
The user has entered four missiles per turn for the USA. The US fires them at targets determined by the firing sequence given above. Let us also assume that France has been declared dead before turn X. (X is an arbitrary turn number somewhere in the middle of the battle.)
Turn X: USA fires on Russia, China, China, then Russia.
Russia, China and England fire their missiles
Turn X+1: USA fires on China, China, Russia, then China.
The other countries then fire.
The key thing to note here is that the target sequence continues in a loop, even between turns. That is, if you shoot the third country in the sequence with your last missile, you will shoot the fourth country with the first missile fired in the next turn. Also note that the US uses all four of its missiles each turn, even though France is no longer available as a target. Remember that all countries that are still alive fire all their available missiles at the beginning of every turn (assuming that any of their targets are still alive).
The DoD (Department of Defense for you civilian types) can get really grumpy when their simulator code enters into infinite loops. Make sure that your code is capable of handling any possible outcome to the battle and outputs an appropriate message.
Sample:
(Boldface indicates user input)
Do you want to play a game?
yes
United States : enter
number of shots per turn? 5
Russia : enter
number of shots per turn? 4
China : enter
number of shots per turn? 6
England : enter
number of shots per turn? 5
France : enter
number of shots per turn? 3
France has died in turn 13 !
England has died in turn 16 !
United States has died in turn 19 !
Russia has died in turn 20 !
China is the
winner in turn 20 !
Sample:
Do you want to play a game?
yes
United States : enter
number of shots per turn? 190
Russia : enter number of shots per turn? 304
China : enter
number of shots per turn? 403
England : enter
number of shots per turn? 203
France : enter number of shots per turn? 211
United States has died in turn 1 !
Russia has died in turn 1 !
China has died in turn 1 !
England has died in turn 1 !
France has died in turn 1 !
ALL PLAYERS ARE DEAD in turn 1 !
Strange game. The only way to win is not to play.