1. 程式人生 > >H - Problem H:Drazil and Date

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;
		}
	}
}