题目链接:

http://codeforces.com/contest/734/problem/D

D. Anton and Chess

time limit per test4 seconds
memory limit per test256 megabytes
#### 问题描述
> 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.
####样例输入
> 2
> 4 2
> R 1 1
> B 1 5

样例输出

YES

题意

给你一个地图很大的国际象棋棋盘,其中白的只有王,黑的有若干个王后(既能走直线,又能走对角),象(走对角线),车(直着走),问你能不能将死白棋的王,(注意,黑棋要攻击到王,王要在该黑棋的攻击范围内,且中间不能跳过其他棋子)

题解

因为中间有其他的点而攻击不到王的只有两种情况:

1、车和王之间夹了一个象。

2、象或者王后和王之间夹了一个车。

所以我们只要分别维护离王最近的八个方向的车、象就可以了。然后枚举每一个黑子,判断中间是否有被阻挡。

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define scf scanf
#define prf printf typedef __int64 LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII; const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-8;
const double PI = acos(-1.0); //start---------------------------------------------------------------------- const int maxn=500000+10; int n;
int x_0,y_0; PII Rrr[8],Brr[8];
int vR[8],vB[8];
PII in[maxn];
char inc[maxn]; LL dis(PII pt){
return (LL)abs(x_0-pt.X)+(LL)abs(y_0-pt.Y);
} int Dir(PII pt){
int res=-1;
if(pt.X==x_0){
if(pt.Y>y_0) res=3;
else res=7;
}
else if(pt.Y==y_0){
if(pt.X>x_0) res=1;
else res=5;
}
else if(pt.X+pt.Y==x_0+y_0){
if(pt.X<x_0&&pt.Y>y_0) res=4;
else res=0;
}else if(pt.X-x_0==pt.Y-y_0){
if(pt.X<x_0&&pt.Y<y_0) res=6;
else res=2;
}
return res;
} int main() {
clr(vR,0);
clr(vB,0);
scf("%d",&n);
scf("%d%d",&x_0,&y_0);
rep(i,0,n){
char type[11];
scf("%s%d%d",type,&in[i].X,&in[i].Y);
inc[i]=type[0];
int dir=Dir(in[i]);
if(dir==-1) continue;
if(type[0]=='R'){
if(dir%2==0){
if(vR[dir]==false){
vR[dir]=true;
Rrr[dir]=in[i];
}else{
if(dis(in[i])<dis(Rrr[dir])){
Rrr[dir]=in[i];
}
}
}
}else if(type[0]=='B'){
if(dir%2){
if(vB[dir]==false){
vB[dir]=true;
Brr[dir]=in[i];
}else{
if(dis(in[i])<dis(Brr[dir])){
Brr[dir]=in[i];
}
}
}
}
}
bool su=false;
rep(i,0,n){
int dir=Dir(in[i]);
if(dir==-1) continue;
if(inc[i]=='B'||inc[i]=='Q'){
if(dir%2==0){
if(vR[dir]==false||vR[dir]&&dis(in[i])<dis(Rrr[dir])){
su=true;
}
}
}
if(inc[i]=='R'||inc[i]=='Q'){
if(dir%2==1){
if(vB[dir]==false||vB[dir]&&dis(in[i])<dis(Brr[dir])){
su=true;
}
}
}
if(su) break;
}
if(su) prf("YES\n");
else prf("NO\n");
return 0;
} //end-----------------------------------------------------------------------

写搓了,其实只要维护八个方向离王最近的点,然后看这些点有没有能攻击到王的就可以了。。

Codeforces Round #379 (Div. 2) D. Anton and Chess 模拟的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #379 (Div. 2) E. Anton and Tree 缩点 直径

    E. Anton and Tree 题目连接: http://codeforces.com/contest/734/problem/E Description Anton is growing a t ...

  4. Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分

    C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...

  5. Codeforces Round #379 (Div. 2) B. Anton and Digits 水题

    B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...

  6. 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 ...

  7. Codeforces Round #379 (Div. 2) E. Anton and Tree —— 缩点 + 树上最长路

    题目链接:http://codeforces.com/contest/734/problem/E E. Anton and Tree time limit per test 3 seconds mem ...

  8. Codeforces Round #379 (Div. 2) C. Anton and Making Potions —— 二分

    题目链接:http://codeforces.com/contest/734/problem/C C. Anton and Making Potions time limit per test 4 s ...

  9. Codeforces Round #379 (Div. 2) E. Anton and Tree 树的直径

    E. Anton and Tree time limit per test 3 seconds memory limit per test 256 megabytes input standard i ...

随机推荐

  1. 巧用开发者工具的控制台来调试页面中的js语句

    因为要弄某网页的一个自动登陆工具,所以需要对此网页中的元素利用js进行选取和操作,复杂的js选取如果直接在头脑中想很容易出错,而且一旦出错也不好判断错误原因. 而浏览器带的开发者工具的控制台功能,就给 ...

  2. JVM的内存区域划分

            JVM的内存区域划分 学过C语言的朋友都知道C编译器在划分内存区域的时候经常将管理的区域划分为数据段和代码段,数据段包括堆.栈以及静态数据区.那么在Java语言当中,内存又是如何划分的 ...

  3. 计算机中的颜色XIV——快速变换颜色的V分量

    基本知识回顾: 计算机中的颜色Color,用RGB模式存储(用R.G.B三个分量表示颜色,每个分量的范围是0—255). 而计算机中的颜色除了用RGB模式表示以外,常见的还有HSV模式(或者是HSB. ...

  4. NOIP2008普及组传球游戏(动态规划)——yhx

    题目描述 上体育课的时候,小蛮的老师经常带着同学们一起做游戏.这次,老师带着同学们一起做传球游戏. 游戏规则是这样的:n个同学站成一个圆圈,其中的一个同学手里拿着一个球,当老师吹哨子时开始传球,每个同 ...

  5. jquery/js实现验证聚焦,失焦

    jquery实现验证聚焦,失焦方法: 我还是喜欢用jquery来实现,不管页面中多少个输入框需要实现聚焦,失焦,都公有,我常用的方法是: 遍历该页面中的input框,获取输入框中的val值,当该输入框 ...

  6. bootstrap学习总结-css样式设计(二)

    首先,很感谢各位园友对我的支持,关于bootstrap的学习总结,我会持续更新,如果有写的不对的地方,麻烦各位给我指正出来哈.关于上篇文章,固定布局和流式布局很关键,如果还不太清楚的可以再看看我写的h ...

  7. Java虚拟机详解03----常用JVM配置参数

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  8. Java Executor并发框架(二)剖析ThreadPoolExecutor运行过程

    上一篇从整体上介绍了Executor接口,从上一篇我们知道了Executor框架的最顶层实现是ThreadPoolExecutor类,Executors工厂类中提供的newScheduledThrea ...

  9. Android 手势识别类 ( 三 ) GestureDetector 源码浅析

    前言:上 篇介绍了提供手势绘制的视图平台GestureOverlayView,但是在视图平台上绘制出的手势,是需要存储以及在必要的利用时加载取出手势.所 以,用户绘制出的一个完整的手势是需要一定的代码 ...

  10. 正则基础之——环视(Lookaround)

    环视基础 环视只进行子表达式的匹配,不占有字符,匹配到的内容不保存到最终的匹配结果,是零宽度的.环视匹配的最终结果就是一个位置. 环视的作用相当于对所在位置加了一个附加条件,只有满足这个条件,环视子表 ...