Shadow Tactics
原创 于 2024-03-27 20:00:18 发布 · 粉丝可见 · 348 阅读 · 5 · 1 · 本内容遵循CC 4.0 BY-SA版权协议 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 GEO检测 · 编辑
文章链接:https://blog.csdn.net/hacker_51/article/details/137087082
本题链接:
题目:


样例:
cobol<br/>1 1<br/>3 3<br/>U 2 2 2<br/> |
思路:
根据题意,隼人的坐标是不会动的,并且士兵只能直线来回行动。
所以这里我们需要分成三种情况。
1、隼人坐标在士兵走动路线之间,如下图:

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

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

从上图,我们可以知道,最短距离路线所对应的某一个(x / y)下标,可以通过隼人的坐标获取,我们只需要判断另一个移动的 (x / y)下标即可。
代码详解如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| #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() {
IOS; int _t = 1;
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; 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; } if(dist(x,y) <= R) { cout << "YES" << endl; return ; } } cout << "NO" << endl; }
|
最后提交:
