UVA 1589(模拟)

 

#include <iostream>
#include<stdio.h>
using namespace std;

char m[15][15];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
int cntx(int a, int b, int y)
{
	if (a > b)
		swap(a, b);
	int cnt = 0;
	for (int i = a + 1; i < b; i++)
	{
		if (m[i][y] != '\0')
		{
			cnt++;
		}
	}
	return cnt;
}
int cnty(int a, int b, int x)
{
	if (a > b)
		swap(a, b);
	int cnt = 0;
	for (int i = a + 1; i < b; i++)
	{
		if (m[x][i] != '\0')
		{
			cnt++;
		}
	}
	return cnt;
}
struct xiangqi
{
	char type;
	int x, y;
};
int main()
{
	int ct = 1;
	int n, bx, by;
//	freopen("C:\\Users\\Lenovo\\Desktop\\out.txt", "w", stdout);
	while (scanf("%d%d%d", &n, &bx, &by) != EOF && (n || bx || by))
	{
		
		xiangqi red[15];
		for (int i = 0; i < 15; i++)
		{
			for (int j = 0; j < 15; j++)
			{
				m[i][j] = '\0';
			}
		}
		char Type;
		int tx, ty;
		bool ans = false;
		int gx=-1, gy=-1;
		for (int i = 0; i < n; i++)
		{
			char t[2];
			scanf("%s", t);
			scanf("%d%d", &tx, &ty);
			m[tx][ty] = t[0];
			red[i].type = t[0];
			red[i].x = tx;
			red[i].y = ty;
			if (t[0] == 'G')
			{
				gx = tx;
				gy = ty;
				
			}
		}
		if (by == gy && cntx(bx, gx, gy) == 0)
		{
			printf("NO\n");
			continue;
		}
		for (int i = 0; i < 4; i++)
		{
			int nx = bx + dx[i];
			int ny = by + dy[i];
			if (nx > 3 || nx < 1 || ny>6 || ny < 4)
				continue;
			ans = false;
			for (int j = 0; j < n; j++)
			{
				if (red[j].x == nx && red[j].y == ny)
					continue;
				if (red[j].type == 'G')
				{
					if (red[j].y == ny)
					{
						int num = cntx(red[j].x, nx, ny);
						if (num == 0)
						{
							ans = true;
							break;
						}
					}
				}
				else if (red[j].type == 'R')
				{
					if (red[j].x == nx)
					{
						int num = cnty(red[j].y, ny, nx);
						if (num == 0)
						{
							ans = true;
							break;
						}
					}
					if (red[j].y == ny)
					{
						int num = cntx(red[j].x, nx, ny);
						if (num == 0)
						{
							ans = true;
							break;
						}
					}
				}
				else if (red[j].type == 'C')
				{
					if (red[j].x == nx)
					{
						int num = cnty(red[j].y, ny, nx);
						if (num == 1)
						{
							ans = true;
							break;
						}
					}
					if (red[j].y == ny)
					{
						int num = cntx(red[j].x, nx, ny);
						if (num == 1)
						{
							ans = true;
							break;
						}
					}
				}
				else if (red[j].type == 'H')
				{
					int xx = red[j].x;
					int yy = red[j].y;
					int detx = nx - red[j].x;
					int dety = ny - red[j].y;
					if (detx == -2 && (dety == -1 || dety == 1) && m[xx - 1][yy] == '\0')
					{
						ans = true;
						break;
					}
					else if (detx == 2 && (dety == -1 || dety == 1) && m[xx + 1][yy] == '\0')
					{
						ans = true;
						break;
					}
					else if (dety == -2 && (detx == -1 || detx == 1) && m[xx][yy - 1] == '\0')
					{
						ans = true;
						break;
					}
					else if (dety == 2 && (detx == -1 || detx == 1) && m[xx][yy + 1] == '\0')
					{
						ans = true;
						break;
					}
				}
			}
			if (!ans)
				break;
		}
		if (ans)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值