(模拟) uva 1589 Xiangqi

总体思路: 将不能走的打标记。

#include <cstring>
#include <iostream>
#include <cstdio>
using namespace std;

struct node{
	int i,j;
	char type;
	
}queue[10];
char xiangqi[12][11];
int beat[11][10],X,Y;
void setwall();
void mark(char , int , int);
bool pd_h(int , int);
int main()
{
	
	int N,rear=0,front=0;
	while(cin >> N && N!=0) {
		memset(xiangqi,0,sizeof(xiangqi));
		setwall();
		memset(beat,0,sizeof(beat));
		memset(queue,0,sizeof(queue));
		front=0;rear=0;
		cin>> X >> Y;
		xiangqi[X][Y] = 'B';
		while(N--) {
			cin >> queue[rear].type >> queue[rear].i >>queue[rear].j;
			xiangqi[queue[rear].i][queue[rear].j] = queue[rear].type;
			rear++;
		}
		while(front<rear) {
			mark(queue[front].type,queue[front].i,queue[front].j);
			front++;
		}
		int ok=0;
		if( X<=2 && !beat[X+1][Y] ) ok=1;
		if( X>=2 && !beat[X-1][Y] ) ok=1;
		if( Y<=5 && !beat[X][Y+1] ) ok=1;
		if( Y>=5 && !beat[X][Y-1] ) ok=1;
		if(ok) cout << "NO" <<endl;
		else cout << "YES" <<endl;
	}
}
void setwall() {
	int i;
	for(i = 1; i <= 10; i++) {
		for(int j = 1; j <= 9; j++)  xiangqi[i][j] = '*';
	}
}
bool pd_h(int x, int y) {
	if(x<=10 && x>=1 && y<=9 && y>=1) return 1;
}
void mark(char type, int i, int j) {
	switch (type)
	{
		case 'G':{//帅的标记 
			int k=1;
			i--;
			while(k)
			{
				beat[i][j]=1;
			    if(xiangqi[i][j] != '*' || i<=1) k--;
			    i--;
			}
			break;
		}
		case 'R':{//车的标记跳过接下来
			int f=i,g=j;
			do {
				i++;
				beat[i][j] = 1;
			} while( (xiangqi[i][j]=='B' || xiangqi[i][j] == '*') && i < 10);
			i = f;
			do {
				i--;
				beat[i][j] = 1;
			} while( (xiangqi[i][j]=='B' || xiangqi[i][j] == '*') && i > 1);
			i = f;
			do {
				j++;
				beat[i][j] = 1;
			} while( (xiangqi[i][j]=='B' || xiangqi[i][j] == '*') && j < 9);
			j = g;
			do {
				j--;
				beat[i][j] = 1;
			} while( (xiangqi[i][j]=='B' || xiangqi[i][j] == '*') && j > 1);
			break;
		}
		case 'C':{//炮 最难的啊啊啊 
		    if(j<4 && i>3) break;
		    else if(j>6 && i>3) break;
		    else if(i>3) {
		    	int f = i;
		    	do i--;
		    	while( xiangqi[i][j]=='*' && i>1);
		    	if(xiangqi[i][j]=='B' || i==1) break;
		    	else {
		    		do {
		    	    	beat[--i][j]=1;
					}while(i>1 && (xiangqi[i][j] == '*' || xiangqi[i][j]=='B'));
				}
 			}
			else {
				int k = 2, g = j;
				while (k && j<9) {
					j++;
					if(k==1) beat[i][j]=1;
					if(xiangqi[i][j]!='*' && xiangqi[i][j]!='B');
					k--;
				}
				j=g;k=2;
 				while (k && j>1)
				{
 					j--;
 					if(k==1) beat[i][j]=1;
 					if(xiangqi[i][j]!='*' && xiangqi[i][j]!='B');
					k--;
				}				 	
			}
		    break;
		}
		case 'H':{// 从周围八个点入手;
			int f = i, g = j;
			f+=2;
			if(xiangqi[i+1][j]=='*') {
				if(pd_h(i+2,j-1)) beat[i+2][j-1]=1;
				if(pd_h(i+2,j+1)) beat[i+2][j+1]=1;
			} 
		    if(xiangqi[i-1][j]=='*') {
				if(pd_h(i-2,j-1)) beat[i-2][j-1]=1;
				if(pd_h(i-2,j+1)) beat[i-2][j+1]=1;
			}
			if(xiangqi[i][j+1]=='*') {
				if(pd_h(i-1,j+2)) beat[i-1][j+2]=1;
				if(pd_h(i+1,j+2)) beat[i+1][j+2]=1;
			}
			if(xiangqi[i][j-1]=='*') {
				if(pd_h(i-1,j-2)) beat[i-1][j-2]=1;
				if(pd_h(i+1,j-2)) beat[i+1][j-2]=1;
			}
		    break; 
		}
	}
	return ;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值