您的位置:首页 > 理论基础 > 计算机网络

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

2015-12-07 12:18 716 查看
#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)

*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  模拟