您的位置:首页 > 其它

CodeForces 734D Anton and Chess 【模拟】

2016-11-18 10:44 363 查看
题目:点击打开链接

题意:给定一个白棋坐标,给出n个黑色的棋子的坐标,表示象,车,女王的中的一个,棋子不能越过另一个棋子,问是否白棋能被吃掉

分析:以白棋为中心,分散中八条横竖斜的射线,储存与最近的黑棋的距离,再遍历一遍黑棋,看是否满足黑棋距离等于该射线的最近距离且能吃掉白棋

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <map>
#define sqr(x) ((x)*(x))
#define PR pair<int,int>
#define MP make_pair
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll long long
const ll INF = (1ULL<<63)-1;
const int inf=0x3f3f3f3f;
const int M=100010;
const int N=500010;
const ll MOD=1000000007;
const double eps=1e-3;
const double pi=acos(-1.0);
using namespace std;
struct node{char s[3];int x,y;}p
;
ll n,sx,sy,x,y,a[8];
char s[3];
ll dis(ll x,ll y) {return abs(x-sx)+abs(y-sy);}
bool judge(ll x,ll y){return abs(x-sx)==abs(y-sy);}
int main()
{
int i,ok=0;
for(i=0;i<8;i++)a[i]=INF;
scanf("%I64d%I64d%I64d",&n,&sx,&sy);
for(i=0;i<n;i++)
{
scanf("%s%I64d%I64d",s,&x,&y);
strcpy(p[i].s,s);p[i].x=x,p[i].y=y;
ll d=dis(x,y);
if(x<sx&&y==sy) a[0]=min(a[0],d);
if(x==sx&&y>sy) a[2]=min(a[2],d);
if(x>sx&&y==sy) a[4]=min(a[4],d);
if(x==sx&&y<sy) a[6]=min(a[6],d);
if(judge(x,y))
{
if(x<sx&&y>sy) a[1]=min(a[1],d);
if(x>sx&&y>sy) a[3]=min(a[3],d);
if(x>sx&&y<sy) a[5]=min(a[5],d);
if(x<sx&&y<sy) a[7]=min(a[7],d);
}
}
for(i=0;i<n;i++)
{
strcpy(s,p[i].s);x=p[i].x,y=p[i].y;
ll d=dis(x,y);
if(s[0]=='R'||s[0]=='Q')
{
if(x<sx&&y==sy&&a[0]>=d) ok=1;
if(x==sx&&y>sy&&a[2]>=d) ok=1;
if(x>sx&&y==sy&&a[4]>=d) ok=1;
if(x==sx&&y<sy&&a[6]>=d) ok=1;
}
if(s[0]=='B'||s[0]=='Q')
{
if(judge(x,y))
{
if(x<sx&&y>sy&&a[1]==d) ok=1;
if(x>sx&&y>sy&&a[3]==d) ok=1;
if(x>sx&&y<sy&&a[5]==d) ok=1;
if(x<sx&&y<sy&&a[7]==d) ok=1;
}
}
}
if(ok) puts("YES");else puts("NO");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: