H - Problem H:Drazil and Date

Click here to have a try
Time limit1000 ms
Memory limit262144 kB

原题:

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
Note
In fourth sample case one possible route is: (0,0)→(0,1)→(0,0)

问题简述:
输入a,b,作为一个坐标(a,b),再输入一个步数s。从坐标轴的(0,0)出发
到(a,b),一个单位为一步,只能上下左右的走,不能斜着走,可以走回头路,再输入一个步数s,利用程序去判断输入的步数是否可以从(0,0)到达(a,b)。

问题分析以及个人感受:

发现|a|+|b|如果为偶数则到达目的地的步数也为偶数,如果为奇数,则到达目的地的步数也为奇数,且|a|+|b|的值就为最小的步数,则s比|a|+|b|的值的差一定为偶数才行。总的来说就是,s与|a|+|b|的值是一类型的数(即都是奇数或者都是偶数),而奇数减奇数等于偶数,偶数减偶数也为偶数。

再尝试一下

VS通过的程序如下:

Status
Accepted Time 46ms
Memory 12kB
Length 268
Lang
Microsoft Visual C++ 2010
Submitted 2018-12-10 22:42:42
RemoteRunId 46855715

#include <iostream>
using namespace std;
int main()
{
	int a, b, s;
	while (cin >> a >> b >> s)
	{
		int sum;
		sum = abs(a) + abs(b);//通过计算发现sum是最少的步数
		if (s >= sum && (sum - s) % 2 == 0)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_43697280/article/details/84948199
今日推荐