【2015ZUFE新生赛网络同步赛I】【模拟】中国象棋 是否可以一步吃敌将

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
int casenum,casei;
char a[12][12];
const int dy[4]={-1,0,0,1};
const int cx[4]={0,-1,1,0};
const int ay[8]={-2,-2,-1,-1,1,1,2,2};
const int ax[8]={-1,1,-2,2,-2,2,-1,1};
const int by[8]={-1,-1,-1,-1,1,1,1,1};
const int bx[8]={-1,1,-1,1,-1,1,-1,1};
const int n=10;
const int m=9;
int yy,xx;
bool ok(int y,int x)
{
	return y>=1&&y<=n&&x>=1&&x<=m;
}
bool checkline()
{
	for(int i=0;i<4;++i)
	{
		int y=yy+dy[i];
		int x=xx+cx[i];
		int num=0;
		while(ok(y,x))
		{
			if(a[y][x]!='.')++num;
			if(num==1&&(a[y][x]=='C'||a[y][x]=='J'))return 1;
			if(num==2&&a[y][x]=='P')return 1;
			y+=dy[i];
			x+=cx[i];
		}
	}
	return 0;
}
bool checkm()
{
	for(int i=0;i<8;++i)
	{
		int y=yy+ay[i];
		int x=xx+ax[i];
		int wy=yy+by[i];
		int wx=xx+bx[i];
		if(ok(y,x)&&a[y][x]=='M'&&a[wy][wx]=='.')return 1;
	}
	return 0;
}
bool checkb()
{
	int st,ed;
	if(yy<=5){st=1;ed=4;}
	else {st=0;ed=3;}
	for(int i=st;i<ed;++i)
	{
		int y=yy+dy[i];
		int x=xx+cx[i];
		if(ok(y,x)&&a[y][x]=='B')return 1;
	}
	return 0;
}
int main()
{
	scanf("%d",&casenum);
	for(casei=1;casei<=casenum;++casei)
	{
		for(int i=1;i<=n;++i)scanf("%s",a[i]+1);
		//找到黑方将的坐标
		for(yy=1;yy<=n;++yy)
		{
			for(xx=1;xx<=m;++xx)
			{
				if(a[yy][xx]=='j')break;
			}
			if(a[yy][xx]=='j')break;
		}
		puts(checkline()||checkm()||checkb()?"YES":"NO");
	}
	return 0;
}
/*
【trick&&吐槽】
1,读题一定要看样例
2,做题常常需要联系实际
3,学会枚举题意!有问题就去尝试

这题就是,象棋的黑棋可能在上或者下,于是士兵的方向要适当调整。
这么蠢的题我竟然没去做,我好蠢!

【题意】
给你一个象棋棋盘,问你是否下一步红棋(大写字符)可以吃掉黑棋(小写字符)的将

【类型】
模拟

【分析】
直接暴力判定
车(将)
炮
马
卒
就可以AC啦!注意方向性哦!

【时间复杂度&&优化】
O(nm)

*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值