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 ...
随机推荐
- 【洛谷P1541】乌龟棋
四维dp #include<cstdio> #include<cstring> using namespace std; ; ],a,b,c,d,n,m; int max(in ...
- .net 泛型运用
DAL层 private DbContext MyContext; public BaseRepository(DbContext context) { MyContext = context; } ...
- C/C++字符串函数之复制函数
突然发现对字符串函数缺乏系统的了解,所以花了一点时间专门整理下,在此记录之,以方便自己及有需要的人使用. C/C++字符串函数的头文件:string.h 复制函数主要有4个,如下: 1.char * ...
- Cocos与Cocos2d-x协作教程——多分辨率适配
http://www.cocoachina.com/bbs/read.php?tid-288123.html Cocos v2.1开始新增了一种新的多分辨率适配方案:流式布局. 这种布局相比Cocos ...
- 【09_242】Valid Anagram
Valid Anagram My Submissions Question Total Accepted: 43694 Total Submissions: 111615 Difficulty: Ea ...
- Hibernate映射问题之OneToOne【自己整理】
首先贴上一个MkYong的例子 stock.java package com.mkyong.stock; import javax.persistence.CascadeType; import ja ...
- C2第三次作业解题报告
看过题解后如果觉得还算有用,请帮忙加点我所在团队博客访问量 http://www.cnblogs.com/newbe/ http://www.cnblogs.com/newbe/p/4069834.h ...
- UITextView
一.由于IOS中的UITextField不支持文本换行,在需要换行的时候.我们可以用UITextView来解决这一问题. 二.创建步骤 1.初始化并设置位置和大小 UITextView *text ...
- 记一次数据库调优过程(IIS发过来SQLSERVER 的FETCH API_CURSOR语句是神马?)
记一次数据库调优过程(IIS发过来SQLSERVER 的FETCH API_CURSOR语句是神马?) 前几天帮客户优化一个数据库,那个数据库的大小是6G 这麽小的数据库按道理不会有太大的性能问题的, ...
- Orchard Compact v1.7.2
1. 仅包留了Core中的Settings和Shapes, 及Modules, Themes和jQuery模块. 2. 添加了对Oracle的支持. 下载地址: 二进制: Orchard.Compac ...