Canadian Computing Competition: 2017 Stage 1, Junior #3
You live in Grid City, which is composed of integer-numbered streets which run east-west (parallel to the -axis) and integer-numbered avenues which run north-south (parallel to the -axis). The streets and avenues have infinite length, and there is a street for every integer -coordinate and an avenue for every -coordinate. All intersections are labelled by their integer coordinates: for example, avenue and street intersect at .
You drive a special electric car which uses up one unit of electrical charge moving between adjacent intersections: that is, moving either north or south to the next street, or moving east or west to the next avenue). Until your battery runs out, at each intersection, your car can turn left, turn right, go straight through, or make a U-turn. You may visit the same intersection multiple times on the same trip.
Suppose you know your starting intersection, your destination intersection and the number of units of electrical charge in your battery. Determine whether you can travel from the starting intersection to the destination intersection using the charge available to you in such a way that your battery is empty when you reach your destination.
Input Specification
The input consists of three lines. The first line contains followed by , indicating the starting coordinate .
The second line contains followed by , indicating the destination coordinate .
The third line contains an integer indicating the initial number of units of electrical charge of your battery.
For 3 of the 15 available marks, .
For an additional 3 of the 15 marks available, .
Output Specification
Output Y
if it is possible to move from the starting coordinate to the destination coordinate using exactly units of electrical charge. Otherwise output N
.
Sample Input 1
3 4
3 3
3
Sample Output 1
Y
Explanation for Sample Output 1
One possibility is to travel from to to to .
Sample Input 2
10 2
10 4
5
Sample Output 2
N
Explanation for Sample Output 2
It is possible to get from to using exactly units of electricity, by going north units.
It is also possible to travel using units of electricity as in the following sequence:
It is also possible to travel using units of electricity from to by the following sequence:
It is not possible to move via any path of length from to , however.
Comments
This question sure wants to stop climate change!
It's Edmonton! https://i.imgur.com/2wcFkLp.png
What? Why Edmonton?
why do i have a fan account???
famous :O
Yes, finally, future is here.
This comment is hidden due to too much negative feedback. Show it anyway.
You must be fun at parties