A. Exercising Walk


A. Exercising Walk


标签

  • 简单思维

简明题意

  • 有一个点在(x,y),再给一个区域(x1,y1)到(x2,y2),(初始位置在这个区域内)。现在给出a、b、c、d,分别表示这个点要向左走a步,向右走b步,向下走c步,向上走d步。现在问你是否可以满足题目的abcd步,且每一步走完后都不超出(x1,y1)到(x2,y2)的范围。

思路

  • 我直接把向上和向下的步数抵消掉,向左和向右的步数抵消掉。
  • 抵消完后,把x、y的移动后的位置计算出来,判断是不是在给定区域内即可。
  • 注意特判一下,给定区域的宽度(或宽度)只有1的话,那么是无法抵消的,走一步就越界了。

注意事项


总结


AC代码

#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring> 
#include<stack>
#include<map>
#include<queue>
#include<cstdio>	
#include<set>
#include<map>
#include<string>
using namespace std;

const int maxn = 2e5 + 10;

int a[maxn];

void solve()
{
	int t;
	cin >> t;
	while (t--)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int x, y, x1, y1, x2, y2;
		cin >> x >> y >> x1 >> y1 >> x2 >> y2;

		bool ok = 0;

		int m, n;
		m = b - a;
		n = d - c;
		if (x2 == x1 && (a >= 1 || b >= 1)) ok = 0;
		else if (y2 == y1 && (c >= 1 || d >= 1)) ok = 0;
		else {
			x += m, y += n;
			if (x >= x1 && x <= x2 && y >= y1 && y <= y2) ok = 1;
			else ok = 0;
		}
		cout << (ok ? "Yes" : "No") << endl;
	}
}
	
int main()
{
	//freopen("Testin.txt", "r", stdin);
	solve();
	return 0;
}
发布了122 篇原创文章 · 获赞 44 · 访问量 6969

猜你喜欢

转载自blog.csdn.net/weixin_42431507/article/details/105236213
今日推荐