Codeforces Round #379 (Div. 2) Anton and Chess
来源:互联网 发布:淘宝图片轮播什么意识 编辑:程序博客网 时间:2024/05/18 01:12
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 on8 to8 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 andy0 ( - 109 ≤ x0, y0 ≤ 109) — coordinates of the white king.
Then follow n lines, each of them contains a character and two integersxi andyi ( - 109 ≤ xi, yi ≤ 109) — type of thei-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
解:找出里白国王最近的8个黑棋的位置,特判这些为哪些棋子即可。
代码:
#include <bits/stdc++.h>using namespace std;char s[10];int main(){ long long n,x,y,nowx,nowy; cin>>n>>x>>y; long long north,south,east,west,en,es,wn,ws; north=south=east=west=en=es=wn=ws=2e10+5; int northjudge,southjudge,eastjudge,westjudge,enjudge,esjudge,wnjudge,wsjudge; for(int i=1;i<=n;i++) { scanf("%s %I64d %I64d",s,&nowx,&nowy); if(s[0]=='B') { if(nowy<y&&nowx==x) { if(y-nowy<west) { westjudge=1; west=y-nowy; } } if(nowy>y&&nowx==x) { if(-y+nowy<east) { eastjudge=1; east=-y+nowy; } } if(nowx>x&&nowy==y) { if(nowx-x<south) { south=nowx-x; southjudge=1; } } if(nowx<x&&nowy==y) { if(-nowx+x<north) { north=-nowx+x; northjudge=1; } } if(nowx+nowy==x+y) { if(nowx>x) { if(nowx-x+y-nowy<ws) { ws=nowx-x+y-nowy; wsjudge=1; } } else { if(-nowx+x-y+nowy<en) { en=-nowx+x-y+nowy; enjudge=1; } } } if(nowx-x==nowy-y) { if(nowx>x) { if(nowx-x-y+nowy<es) { es=nowx-x-y+nowy; esjudge=1; } } else { if(-nowx+x+y-nowy<wn) { wn=-nowx+x+y-nowy; wnjudge=1; } } } } if(s[0]=='R') { if(nowy<y&&nowx==x) { if(y-nowy<west) { westjudge=2; west=y-nowy; } } if(nowy>y&&nowx==x) { if(-y+nowy<east) { eastjudge=2; east=-y+nowy; } } if(nowx>x&&nowy==y) { if(nowx-x<south) { south=nowx-x; southjudge=2; } } if(nowx<x&&nowy==y) { if(-nowx+x<north) { north=-nowx+x; northjudge=2; } } if(nowx+nowy==x+y) { if(nowx>x) { if(nowx-x+y-nowy<ws) { ws=nowx-x+y-nowy; wsjudge=2; } } else { if(-nowx+x-y+nowy<en) { en=-nowx+x-y+nowy; enjudge=2; } } } if(nowx-x==nowy-y) { if(nowx>x) { if(nowx-x-y+nowy<es) { es=nowx-x-y+nowy; esjudge=2; } } else { if(-nowx+x+y-nowy<wn) { wn=-nowx+x+y-nowy; wnjudge=2; } } } } if(s[0]=='Q') { if(nowy<y&&nowx==x) { if(y-nowy<west) { westjudge=3; west=y-nowy; } } if(nowy>y&&nowx==x) { if(-y+nowy<east) { eastjudge=3; east=-y+nowy; } } if(nowx>x&&nowy==y) { if(nowx-x<south) { south=nowx-x; southjudge=3; } } if(nowx<x&&nowy==y) { if(-nowx+x<north) { north=-nowx+x; northjudge=3; } } if(nowx+nowy==x+y) { if(nowx>x) { if(nowx-x+y-nowy<ws) { ws=nowx-x+y-nowy; wsjudge=3; } } else { if(-nowx+x-y+nowy<en) { en=-nowx+x-y+nowy; enjudge=3; } } } if(nowx-x==nowy-y) { if(nowx>x) { if(nowx-x-y+nowy<es) { es=nowx-x-y+nowy; esjudge=3; } } else { if(-nowx+x+y-nowy<wn) { wn=-nowx+x+y-nowy; wnjudge=3; } } } } } int flag=0; if(eastjudge!=1&&east!=2e10+5) flag=1; if(westjudge!=1&&west!=2e10+5) flag=1; if(northjudge!=1&&north!=2e10+5) flag=1; if(southjudge!=1&&south!=2e10+5) flag=1; if(enjudge!=2&&en!=2e10+5) flag=1; if(esjudge!=2&&es!=2e10+5) flag=1; if(wnjudge!=2&&wn!=2e10+5) flag=1; if(wsjudge!=2&&ws!=2e10+5) flag=1; if(flag) puts("YES"); else puts("NO"); return 0;}
- Codeforces Round #379 (Div. 2) 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) -- D. Anton and Chess (if else 的水题)
- Codeforces Round #379 (Div. 2) D. Anton and Chess —— 基础题
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions
- Codeforces Round #379 (Div. 2) F. Anton and School
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions
- Anton and Chess CodeForces
- Codeforces Round #253 (Div. 2)A. Anton and Letters
- Codeforces Round #253 (Div. 2) A. Anton and Letters
- [排列组合]Codeforces Round #324 (Div. 2)E - Anton and Ira
- Codeforces Round #329 (Div. 2)B. Anton and Lines
- Codeforces Round #329 (Div. 2)B. Anton and Lines
- Codeforces Round #329 (Div. 2)B. Anton and Lines
- Codeforces Round #329 (Div. 2) 593B - Anton and Lines
- Codeforces Round #404 (Div. 2) D. Anton and School
- Codeforces Round #404(Div. 2)D. Anton and School
- JAVA注释应用小例子
- android 开发笔记 图片轮播
- PCL可视化例程
- InnoDB最佳实现
- 树莓派学习笔记——webiopi装配与入门
- Codeforces Round #379 (Div. 2) Anton and Chess
- Jenkins简介
- Mysql 存储引擎中InnoDB与Myisam的主要区别
- 经典的机器学习方面源代码库
- Lru算法在Android中的应用
- ListView最基本的使用方法BaseAdapter(三)
- 程序如何使用cmake链接至libcaffe.so库文件
- PHP使用traits实现代码复用
- 树莓派学习笔记——webiopi网页统制LED