A - Two Semiknights Meet

Description

A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.

Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.

Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.

Please see the test case analysis.


思路是 因为只有8个格子 而且要求同时移动,因此必然只要满足

		if ((abs(x1-x2)==4||abs(x1-x2)==0)&&(abs(y1-y2)==4||abs(y1-y2)==0))

就可以了

这是后来才发现的,之前用的是两个dfs+该条件   dfs多余了 


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue> 
#include <set>
#include <vector>
using namespace std;

int map[505][505]; 

int main()
{
	int i,j;
	
	int t;
	cin>>t;
 
	while(t--)
	{ 
		getchar();
		int x1,y1,x2,y2;
		int line=0;
		for (i=1;i<=8;i++)
		{
			for (j=1;j<=8;j++)
			{
				scanf("%c",&map[i][j]);
				if (map[i][j]=='K')
				{
					if (line==0)
					{
						x1=i;
						y1=j;
						line=1;
					}
					else
					{
						x2=i;y2=j;
					}
				}
			}
			getchar();
		}
		 
		if ((abs(x1-x2)==4||abs(x1-x2)==0)&&(abs(y1-y2)==4||abs(y1-y2)==0))
		{	
			printf("YES\n");
		}
		else
			printf("NO\n");
		
		
	}
	return 0; 
	
} 





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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值