第一次周赛H题

问题链接:https://vjudge.net/problem/CodeForces-515A#author=0

问题简述:第一行输入a,b,s三个变量,Drazil的家在(0,0),Varda的家在(a,b),Drazil去Varda家的行进路线是随机的,Drazil说他走了s步到达Varda的家,问是否合理?

问题PE点:需要考虑综合情况,例如s必须要大于或等于a+b的绝对值。

程序说明:取a,b绝对值,判断是否满足两种情况之一。

AC代码:

#include<cmath>
#include <iostream>
using namespace std;
int main()
{
	int a, b, s;
	cin >> a >> b >> s;
	if (s - abs(a) - abs(b) == 0)
	{
		cout << "Yes";
	}
	else if (s - abs(a) - abs(b) > 0 && (s - abs(a) - abs(b)) % 2 == 0)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_43973189/article/details/84934099
今日推荐