DMOPC '16 Contest 3 P1 - Leading Basic Shots

View as PDF

Submit solution

Points: 3
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

Welcome to Naval Academy lesson #1: Leading Basic Shots!

In the world of Naval warfare, you will be required to assault enemy ships from extremely large distances with high caliber shells. Like all projectiles, shells require time to travel, and over the span of many kilometers, the difference in time between the moment you fire and the moment it hits is considerably large. This means that if you aim at the enemy ship and fire, the ship will have most likely moved away from its initial location, resulting in a miss. This is the importance of leading the shot.

Leading is when you aim and fire ahead of the target, predicting where the ship will be when your shells travels the distance between you and the enemy ship.

To calculate lead, you will fire an initial shot and use it as a guideline for your second shot. If the shot is in front of the ship, your lead is too large. If the shot is behind the ship, your lead is too short.

Calculating how far you must lead is an important skill for captains such as yourself. Let's begin with a simple situation:

  • The enemy ship is traveling in a circle around you (The distance between you and the ship is constant)
  • The enemy ship's speed is constant

An initial shot will be fired, and you must use the information from that shot to calculate the lead.

Input Specification

The first line of the input will contain an integer N_1 (1 \le N_1 \le 1\,000), representing the distance, in km, between the enemy ship and where the initial shot was aimed. Assume the shot is always aimed in front of the ship.

The second line will contain a string S, either Infront or Behind, denoting the direction in which the shot landed in respect to the enemy ship.

The final line will contain an integer N_2 (1 \le N_2 \le 1\,000), representing the distance, in km, between the enemy ship and where the initial shot landed in the direction of S in respect to the enemy ship.

Output Specification

Output I, the distance, in km, in front of the ship that you must aim for your second shot to hit.

Sample Input

10
Infront
2

Sample Output

8

Explanation

The initial shot was aimed 10 km in front of the enemy ship and landed 2 km Infront of it. This means that if you were to fire 10 km in front of the enemy ship, the lead will be 2 km too large. Therefore, you must fire 8 km ahead to hit the enemy ship.


Comments

There are no comments at the moment.