Codeforces Round #379 (Div. 2) D. Anton and Chess 水题
D. Anton and Chess
题目连接:
http://codeforces.com/contest/734/problem/D
Description
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".
Input
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.
Output
The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.
Sample Input
2
4 2
R 1 1
B 1 5
Sample Output
YES
Hint
题意
一个无限大的平面,给你一个King的位置,再给你其他棋子的位置,问你这个King是不是正在被人将军。
题解:
只用考虑King的八个方向最近的棋子是什么就好了,记录一下就行了。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+6;
long long x[maxn],y[maxn],xx,yy;
char a[3][3];
long long dis[3][3];
string s;
int f(int x){
if(x==0)return 1;
if(x>0)return 2;
if(x<0)return 0;
}
int main()
{
int n;scanf("%d",&n);
scanf("%lld%lld",&xx,&yy);
for(int i=0;i<3;i++)for(int j=0;j<3;j++)dis[i][j]=2e15,a[i][j]='W';
for(int i=1;i<=n;i++){
cin>>s>>x[i]>>y[i];
x[i]-=xx,y[i]-=yy;
if(x[i]!=0&&y[i]!=0&&abs(x[i])!=abs(y[i]))continue;
if(dis[f(x[i])][f(y[i])]>max(abs(x[i]),abs(y[i]))){
dis[f(x[i])][f(y[i])]=max(abs(x[i]),abs(y[i]));
a[f(x[i])][f(y[i])]=s[0];
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
if(a[i][j]=='Q')return puts("YES");
if((i+j)%2==0&&a[i][j]=='B')return puts("YES");
if((i+j)%2==1&&a[i][j]=='R')return puts("YES");
}
}
puts("NO");
}
Codeforces Round #379 (Div. 2) D. Anton and Chess 水题的更多相关文章
- Codeforces Round #379 (Div. 2) D. Anton and Chess —— 基础题
题目链接:http://codeforces.com/contest/734/problem/D D. Anton and Chess time limit per test 4 seconds me ...
- Codeforces Round #379 (Div. 2) B. Anton and Digits 水题
B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...
- Codeforces Round #379 (Div. 2) A. Anton and Danik 水题
A. Anton and Danik 题目连接: http://codeforces.com/contest/734/problem/A Description Anton likes to play ...
- Codeforces Round #379 (Div. 2) D. Anton and Chess 模拟
题目链接: http://codeforces.com/contest/734/problem/D D. Anton and Chess time limit per test4 secondsmem ...
- Codeforces Round #404 (Div. 2) B. Anton and Classes 水题
B. Anton and Classes 题目连接: http://codeforces.com/contest/785/problem/B Description Anton likes to pl ...
- Codeforces Round #404 (Div. 2) A - Anton and Polyhedrons 水题
A - Anton and Polyhedrons 题目连接: http://codeforces.com/contest/785/problem/A Description Anton's favo ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #379 (Div. 2) A B C D 水 二分 模拟
A. Anton and Danik time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
随机推荐
- css样式注意
CSS3 font-face定义的字体使用时有时候用引号,有时候不用,很奇怪,如 @font-face{ font-family: Roboto-Black; src: url('../package ...
- JS-定时器换背景
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content=&q ...
- grunt-replace和grunt-include-replace问题
关于最近在做的项目要用到的grunt-replace和grunt-include-replace,百度上很多将grunt的压缩合并的教程,可是很少讲关于这两个插件的教程,不过官网上有教程,我就是按照官 ...
- 『TCP/IP详解——卷一:协议』读书笔记——05
2013-08-19 22:35:57 2.6 PPP:点对点协议 PPP点对点协议修改了SLIP协议中的所有缺陷: 1. 在串联链路上封装IP数据报的方法.PPP即支持数据为8位&无奇偶检验 ...
- SQL语句汇总(一)——数据库与表的操作以及创建约束
首先,非常感谢大家对上篇博文的支持,真是让本菜受宠若惊,同时对拖了这么久才出了此篇表示抱歉. 前言:此文旨在汇总从建立数据库到联接查询等绝大部分SQL语句.SQL语句虽不能说很多,但稍有时间不写就容易 ...
- Unity3.0基于约定的自动注册机制
前文<Unity2.0容器自动注册机制>中,介绍了如何在 Unity 2.0 版本中使用 Auto Registration 自动注册机制.在 Unity 3.0 版本中(2013年),新 ...
- 冲刺阶段 day 4
day4 项目进展 今天上完软件工程后我们便聚在宿舍,总结了一下昨天的工作,讨论完成了昨天未完成的 注册功能,然后趁热打铁,构建了学生管理这部分的窗体搭建及部分代码的编写. 存在的问题 代码记不得.在 ...
- UTL_FILE建文件失败“ORA-29280: 目录路径无效”错误
存储过程写文件需要配置可写的目录,具体是utl_file_dir这个参数,把UTL_FILE输出的目录写到这个参数,如果不限制,可以令utl_file_dir=* 查看: SQL> sh ...
- 写给自己看的Linux运维基础(二) - Apache/MySQL. 安全设置. 定时任务
本文使用环境为CentOS 6 Apache, PHP, MySQL等常用软件均可通过yum安装包获取 yum install httpd php mysql-server # mysql: 客户端; ...
- jenkins和docker 使用docker作为slave
使用docker作为jenkins slave. 文章来自:http://www.ciandcd.com文中的代码来自可以从github下载: https://github.com/ciandcd 参 ...