H - Problem H

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".
问题链接:https://vjudge.net/contest/274223#problem/H
问题简述:输入坐标a,b,和步数s,判断是否能从(0,0)出发经s步到(a,b)。
问题分析:除了到(a,b)所必要的步数外,若剩余步数为偶数,则满足条件。
程序说明:用if语句取a,b的绝对值,再判断。
AC通过的C++程序如下:

include<iostream>

using namespace std;
int main()
{
int s, a, b,n;
cin >> a >> b>> s;
if (a < 0)
a = 0 - a;
if (b < 0)
b = 0 - b;
n = s - a - b;
if (n % 2 != 0||n<0)
cout << "NO";
else cout << "YES";
return 0;
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,160评论 0 10
  • The Inner Game of Tennis W Timothy Gallwey Jonathan Cape ...
    网事_79a3阅读 14,269评论 3 20
  • 第三周+黄幼红+第4章,第5章读书笔记 本周学习两章节的内容,特别适合我这样的投资懒小白,指数基金很多,如何买卖是...
    云鉴1378阅读 754评论 0 0
  • mac下的P2P下载工具目前只有迅雷了,可是大家都知道mac下只有“会员迅雷”才能下载,没会员就是个废物。对于冷门...
    weishu阅读 5,692评论 7 18
  • 真的没有必要再坚持了,他好,他坏,都不会和你产生关系。
    七千夜阅读 838评论 0 0