HDU ACM 1728解题报告

每次直走一个方向

这样走到底后,换方向就相当于一次转弯了

 

ContractedBlock.gif ExpandedBlockStart.gif Code
#include <iostream>
#include 
<queue>
using namespace std;
int m,n,sx,sy,ex,ey,k,dir[4][2= {{0,1},{0,-1},{1,0},{-1,0}};
char map[120][120];
struct node
{
    
int x,y,s;
};
void BFS()
{
    queue
<node> q;
    node f,l;
    f.x 
= sx;
    f.y 
= sy;
    f.s 
= -1;
    q.push(f);
    
while (!q.empty())
    {
        f 
= q.front();
        q.pop();
        map[f.x][f.y] 
= '*';
        
for (int i = 0;i < 4;i++)
        {
            l.x 
= f.x + dir[i][0];
            l.y 
= f.y + dir[i][1];
            
while (l.x > 0 && l.x <= m && l.y > 0 && l.y <= n)
            {
                
if(map[l.x][l.y] == '*')
                    
break;
                l.s 
= f.s + 1;
                
if(l.x == ex && l.y == ey && l.s <= k)
                {
                    printf(
"yes\n");
                    
return;
                }
                
if(l.s <= k)
                    q.push(l);
                
                l.x 
= l.x + dir[i][0];
                l.y 
= l.y + dir[i][1];
            }
        }
    }
    printf(
"no\n");
}
int main()
{
    
int i,j,t;
    scanf(
"%d",&t);
    
while (t--)
    {
        scanf(
"%d %d",&m,&n);
        
        
for (i = 1;i <= m;i++)
            
for(j = 1;j <= n;j++)
                cin 
>> map[i][j];
            
        scanf(
"%d %d %d %d %d",&k,&sy,&sx,&ey,&ex);

        
if(sx == ex && sy == ey)
            printf(
"yes\n");
        
else
            BFS();

    }
    
return 0;
}


 

转载于:https://www.cnblogs.com/cnnbboy/archive/2009/04/14/1435891.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值