Canadian Computing Competition: 1997 Stage 2, Day 1, Problem 2
Earth is being invaded by space aliens. Earth defence forces have rallied a number of anti-spacecraft guns. However, they have a bug in their aiming hardware: initially they are aimed straight up, and this aim can only be adjusted downward.
Thousands of alien craft are streaking towards Earth as we speak -- and yes, some of them are even aimed at Canada. The Earth defence forces must now come into play. Each gun can fire as many shots as necessary, and can be re-fired as often and as quickly as necessary, but only to the same or lower setting. Thus if a spacecraft came in at height
Input Specification
The data will consist of several sets of data. The first line will contain
Output Specification
For each set, output one integer specifying the minimum number of guns required to eliminate EVERY alien craft.
Sample Input
1
10
4
2
3
4
5
3
1
4
2
5
Sample Output
4
Comments
How is the sample output 4? 4 > 2, 2 < 3, 3 < 4, 4 < 5, 5 > 3, 3 > 1, 1 < 4, 4 > 2, 2 < 5 If we set the gun count at 1 to start and increment it at 4 < 5, 1 < 4, and 2 < 5 that gives 4. That is not consistent though because why would we increase the gun count at all between both 5s if we did not for the increasing sequence after the first 4?
Seems like you're trying to take out the first 4 aliens with 1 gun. The gun can go from height 4 to height 2, but can't go from height 2 to height 3, so this doesn't work.
One way to take out the aliens using 4 guns is: