Codeforces Round #379 (Div. 2) -- D. Anton and Chess (if else 的水题)
来源:互联网 发布:深圳华夏软件学校招生 编辑:程序博客网 时间:2024/04/30 11:43
大体题意:
给你国际象棋一种残局,问白方是否已经输掉! (下一步该黑方走) 黑方的棋有三种 (只能横着走 和 只能斜着走 和 既能横着走又能斜着走! = = 没玩过国际象棋 (勿喷!))
思路:
因为这个棋盘太大了,最大20亿×20亿 肯定不能乱扫!
其实思路很简单:
直接统计出 白方棋子 八个方向上 最近的黑方棋子即可! 然后 讨论这八个方向是否有棋,有棋的话能否被吃掉!
参考下if else 的代码把 = =:
#include <bits/stdc++.h>#define ps push_back#define fi first#define se second#define mr make_pairusing namespace std;typedef long long ll;typedef unsigned long long LLU;const int inf = (0x3f3f3f3f) << 1;const double eps = 1e-10;const double pi = acos(-1.0);char s[20];int a[8];char b[8];int main(){ int n; scanf("%d",&n); int x0,y0; scanf("%d %d",&x0,&y0); a[0] = -inf,a[1] = inf,a[2] = -inf,a[3] = inf; a[4] = -inf,a[5] = inf,a[6] = inf,a[7] = -inf; memset(b,0,sizeof b); for (int i = 0; i < n; ++i){ int r,c; scanf("%s %d %d", s, &r, &c); if (r == x0){ // yes if (c < y0){ if (c > a[0]){ a[0] = c; b[0] = s[0]; } } else { if (c < a[1]){ a[1] = c; b[1] = s[0]; } } } else if (c == y0){ if (r < x0){ if (r > a[2]){ a[2] = r; b[2] = s[0]; } } else { if (r < a[3]){ a[3] = r; b[3] = s[0]; } } } else if (r - c == x0 - y0){ if (r + c < x0 + y0){ if (r + c > a[4]){ a[4] = r + c; b[4] = s[0]; } } else { if (r+c < a[5]){ a[5] = r+c; b[5] = s[0]; } } } else if (r + c == x0 + y0){ if (r-c > x0-y0){ if (r-c < a[6]){ a[6] = r-c; b[6] = s[0]; } } else { if (r-c > a[7]){ a[7] = r-c; b[7] = s[0]; } } } } bool ok = 0; for (int i = 0; i < 4; ++i){ if (b[i] == 'R' || b[i] == 'Q') ok = 1; } for (int i = 4; i < 8; ++i){ if (b[i] == 'B' || b[i] == 'Q') ok = 1; }// printf("%c\n",b[7]); if (ok)puts("YES"); else puts("NO"); return 0;}/**3-1000000000 -1000000000B 1000000000 -1000000000B -1000000000 1000000000B 1000000000 10000000003-1 -1B 1 -1B -1 1B 1 1**/
Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead.
The first task he faced is to check whether the king is in check. Anton doesn't know how to implement this so he asks you to help.
Consider that an infinite chess board contains one white king and the number of black pieces. There are only rooks, bishops and queens, as the other pieces are not supported yet. The white king is said to be in check if at least one black piece can reach the cell with the king in one move.
Help Anton and write the program that for the given position determines whether the white king is in check.
Remainder, on how do chess pieces move:
- Bishop moves any number of cells diagonally, but it can't "leap" over the occupied cells.
- Rook moves any number of cells horizontally or vertically, but it also can't "leap" over the occupied cells.
- Queen is able to move any number of cells horizontally, vertically or diagonally, but it also can't "leap".
The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of black pieces.
The second line contains two integers x0 and y0 ( - 109 ≤ x0, y0 ≤ 109) — coordinates of the white king.
Then follow n lines, each of them contains a character and two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — type of the i-th piece and its position. Character 'B' stands for the bishop, 'R' for the rook and 'Q' for the queen. It's guaranteed that no two pieces occupy the same position.
The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.
24 2R 1 1B 1 5
YES
24 2R 3 3B 1 5
NO
Picture for the first sample:
Picture for the second sample:
- Codeforces Round #379 (Div. 2) -- D. Anton and Chess (if else 的水题)
- Codeforces Round #379 (Div. 2) D. Anton and Chess
- Codeforces Round #379 (Div. 2)-D. Anton and Chess
- Codeforces Round #379 (Div. 2) D. Anton and Chess —— 基础题
- Codeforces Round #379 (Div. 2) Anton and Chess
- Codeforces Round #404 (Div. 2)(D)Anton and School
- Codeforces Round #404 (Div. 2) D. Anton and School
- Codeforces Round #404(Div. 2)D. Anton and School
- Codeforces Round #404 (Div. 2) D. Anton and School
- codeforces round#404(div.2) D. Anton and School
- Codeforces Round #404 (Div. 2) D. Anton and School
- Codeforces Round #404 (Div. 2) D. Anton and School
- Codeforces Round #404 (Div. 2) D. Anton and School
- Codeforces Round #404 (Div. 2):D. Anton and School
- Codeforces Round #404 (Div. 2) D. Anton and School
- Codeforces Round #281 (Div. 2)-D. Vasya and Chess
- Codeforces Round #379 (Div. 2) -- C. Anton and Making Potions(简单的分类讨论 + 二分)
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions
- 屏幕类,用于全屏程序&显示任务栏
- 浮点型 比较
- 抢红包背后的技术点
- liferay中自定义字段及部分路由说明
- k-means算法学习
- Codeforces Round #379 (Div. 2) -- D. Anton and Chess (if else 的水题)
- Python 内置函数 locals()和 globals()
- 双链表的插入学习(C和指针)
- Unity3D都有哪些坑
- TCP/IP和UDP的基础理解(1)
- 使用conlleval.pl对CRF测试结果进行评价的方法
- 扯淡nginx的sendfile零拷贝的概念
- [基于ionic开发]开发教程lesson01之环境安装
- Spring jpa配置