TopCoder problem "Towers" used in SRM 418 (Division II Level One)



Problem Statement

    As a serious strategy-games player, you decided to solve one of the most common problems - attacking your opponent's guard towers.



Before the attack, you've got myUnits soldiers. Each soldier in a single round inflicts 1 hit point of damage to one of the towers.

Your opponent doesn't have any soldiers. However, he's got numT towers with hpT hit points each. Each tower kills attackT of your soldiers per round.



The course of one round:

1. Each soldier in your army attacks a tower of your choice for 1 hit point of damage. When a tower loses all its hit points, it is destroyed. You can pick the tower independently for each soldier.

2. Your opponent attacks. He will kill k*attackT of your soliders, where k is the number of remaining towers.



Your task is to destroy all the towers. If it is possible, return the minimum number of rounds you need to do this. Otherwise return -1.



 

Definition

    
Class:Towers
Method:attack
Parameters:int, int, int, int
Returns:int
Method signature:int attack(int myUnits, int hpT, int attackT, int numT)
(be sure your method is public)
    
 

Notes

-More than one soldier can attack the same tower in the same round.
 

Constraints

-myUnits will be between 1 and 1000000, inclusive.
-hpT, attackT, numT will each be between 1 and 10000, inclusive.
 

Examples

0)
    
13
2
3
8
Returns: 2
Round 1:

- Your soldiers destroy 6 towers leaving one tower with 1 hit point and one tower with 2 hit points.

- Your opponent attacks and kills 2*3=6 of your soldiers.



Round 2:

- You have 7 soldiers remaining, which is more than enough to take out the 3 hit points of the remaining towers.
1)
    
10
6
8
2
Returns: 2
2)
    
10
6
9
2
Returns: -1
3)
    
1
1
1
1
Returns: 1
4)
    
10000
10
2
2789
Returns: 10
5)
    
2
1
1
3
Returns: 2

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=9945

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13509&pm=9945

Writer:

Rydberg

Testers:

PabloGilberto , Olexiy , Mike Mirzayanov , ivan_metelsky , darnley

Problem categories:

Simulation