Shadow Tactics

本题链接:

题目:

样例:

输入
1 1
3 3
U 2 2 2
输出
YES

思路:

        根据题意,隼人的坐标是不会动的,并且士兵只能直线来回行动。

        所以这里我们需要分成三种情况。

        1、隼人坐标在士兵走动路线之间,如下图:

       2、隼人坐标在士兵走动路线外面的一侧,如下图:

        3、隼人坐标在士兵走动路线外面的另一侧,如下图:

        从上图,我们可以知道,最短距离路线所对应的某一个(x / y)下标,可以通过隼人的坐标获取,我们只需要判断另一个移动的 (x / y)下标即可。

代码详解如下:

#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#define endl '\n'
#define x first
#define y second
#define int long long
#define YES puts("YES")
#define NO puts("NO")
#define umap unordered_map
#define All(x) x.begin(),x.end()
#pragma GCC optimize(3,"Ofast","inline")
#define IOS std::ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)
using namespace std;
const int N = 2e6 + 10;
inline void solve();

signed main()
{
//	freopen("a.txt", "r", stdin);
	IOS;
	int _t = 1;
// 	cin >> _t;
	while (_t--)
	{
		solve();
	}
	return 0;
}
using PII = pair<int,int>;

PII peo; // 隼人 坐标

// 求 当前点 和 隼人的最短距离
inline double dist(double x,double y)
{
	return sqrt(pow(x - peo.x,2)*1.0 + pow(y - peo.y,2)*1.0);
}

inline void solve()
{
	int n,R;
	cin >> n >> R;
	cin >> peo.x >> peo.y;
	
	while(n--)
	{
		char c;
		int x,y,w;
		cin >> c >> x >> y >> w;
		
		// 判断当前点到隼人距离是否在 R 内
		// 是则,隼人 被发现
		if(dist(x,y) <= R)
		{
			cout << "YES" << endl;
			return ;
		}
		
		if(c == 'U')
		{
			// 判断是否在线段之间,反之 则在线段端点
			if(y <= peo.y and peo.y <= y + w) y = peo.y;
			else if(peo.y > y + w) y += w;
		}
		
		if(c == 'D')
		{
			// 判断是否在线段之间,反之 则在线段端点
			if(y - w <= peo.y and peo.y <= y) y = peo.y;
			else if(peo.y < y - w) y -= w;
		}
		
		if(c == 'L')
		{
			// 判断是否在线段之间,反之 则在线段端点
			if(x - w <= peo.x and peo.x <= x) x = peo.x;
			else if(peo.x < x - w) x -= w;
		}
		
		if(c == 'R')
		{
			// 判断是否在线段之间,反之 则在线段端点
			if(x <= peo.x and peo.x <= x + w) x = peo.x;
			else if(peo.x > x + w) x += w;
		}
		
		// 判断移动的最短距离坐标点到隼人距离是否在 R 内
		// 是则,隼人 被发现
		if(dist(x,y) <= R)
		{
			cout << "YES" << endl;
			return ;
		}
	}
	
	// 都没有被发现,输出 NO
	cout << "NO" << endl;
}

最后提交:

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值