CodeForces - 515A
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil’s home is located in point (0, 0) and Varda’s home is located in point (a, b). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (x, y) he can go to positions (x + 1, y), (x - 1, y), (x, y + 1) or (x, y - 1).
Unfortunately, Drazil doesn’t have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (a, b) and continue travelling.
Luckily, Drazil arrived to the position (a, b) successfully. Drazil said to Varda: “It took me exactly s steps to travel from my house to yours”. But Varda is confused about his words, she is not sure that it is possible to get from (0, 0) to (a, b) in exactly s steps. Can you find out if it is possible for Varda?
Input
You are given three integers a, b, and s ( - 109 ≤ a, b ≤ 109, 1 ≤ s ≤ 2·109) in a single line.
Output
If you think Drazil made a mistake and it is impossible to take exactly s steps and get from his home to Varda’s home, print “No” (without quotes).
Otherwise, print “Yes”.
Examples
Input
5 5 11
Output
No
Input
10 15 25
Output
Yes
Input
0 5 1
Output
No
Input
0 0 2
Output
Yes
问题简述:女方家位于(a,b),男方家位于(0,0),每次男方只能移动一单位(沿x轴或y轴方向),且可以在到达男方家或者女方家后继续移动。输入a,b,以及男方移动次数s,如果男方可以在走完s步数后刚刚好到达女方家,则输出yes,否则输出no。
问题分析:首先步数得大于等于到女方家的最短路程,其次如果步数减去女方家的最短路程数得到的是奇数,则无法恰好到达女方家。
程序分析:判断s和最小路程数|a|+|b|的大小,再判断s和它的差值是否为偶数,都满足则输出yes。
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int a, b, s;
cin >> a >> b >> s;
if (s-(abs(a) + abs(b))>=0&& (s - (abs(a) + abs(b))) %2==0)cout << "Yes";
else cout << "No";
return 0;
}