hdu 2102 A计划

51 篇文章 0 订阅

http://acm.hdu.edu.cn/showproblem.php?pid=2102

分析:遇到‘#’就跳到另外一层,本来想到两层相同位置同时为’#‘会发生冲突,没想到还是脑抽了认为已经考虑到这种情况了,还狂找bug,看来还是不够细心和自信,努力之

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

const int NM=11;
char str1[NM][NM],str2[NM][NM];
int a[4][2]={-1,0,1,0,0,-1,0,1},x1,y1,x2,y2,f1,f2,N,M,T;
struct ABC{
	int x,y,tt,f;
};

void BFS()
{
	queue<ABC>q1;
	ABC t,p;
	int i;
	
	t.x=x1,t.y=y1,t.tt=0,t.f=f1;
	q1.push(t);
	while(!q1.empty())
	{
		t=q1.front();q1.pop();
		if(t.tt>T) break;
		if(t.x==x2&&t.y==y2&&t.f==f2)
		{
			cout<<"YES"<<endl;
			return;
		}
		for(i=0;i<4;i++)
		{
			p.x=t.x+a[i][0],p.y=t.y+a[i][1],p.tt=t.tt+1;
			if(t.f==1)
			{
				if(p.x>=0&&p.x<N&&p.y>=0&&p.y<M)
				{
					if(str1[p.x][p.y]=='#')
					{
						p.f=2;
						if(str2[p.x][p.y]!='*')
						{q1.push(p);str2[p.x][p.y]='*';}
					}
					else 
					{
						p.f=1;
						if(str1[p.x][p.y]!='*')
						{q1.push(p);str1[p.x][p.y]='*';}
					}
				}
			}
			else
			{
				if(p.x>=0&&p.x<N&&p.y>=0&&p.y<M)
				{
					if(str2[p.x][p.y]=='#')
					{
						p.f=1;
						if(str1[p.x][p.y]!='*')
						{q1.push(p);str1[p.x][p.y]='*';}
					}
					else 
					{
						p.f=2;
						if(str2[p.x][p.y]!='*')
						{q1.push(p);str2[p.x][p.y]='*';}
					}
				}
			}
		}
	}
	cout<<"NO"<<endl;
}

int main()
{
	int C,i,j;
	cin>>C;
	while(C--)
	{
		cin>>N>>M>>T;
		for(i=0;i<N;i++)
		{
			cin>>str1[i];
			for(j=0;j<M;j++)
			{
				if(str1[i][j]=='S')
					x1=i,y1=j,f1=1;
				if(str1[i][j]=='P')
					x2=i,y2=j,f2=1;
			}
		}
		for(i=0;i<N;i++)
		{
			cin>>str2[i];
			for(j=0;j<M;j++)
			{
				if(str2[i][j]=='S')
					x1=i,y1=j,f1=2;
				if(str2[i][j]=='P')
					x2=i,y2=j,f2=2;
				if(str2[i][j]=='#'&&str1[i][j]=='#')
					str2[i][j]=str1[i][j]='*';
			}
		}
		BFS();
	}
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值