HLG1433泉水

这道题充分的验证了我的马虎。。。。

   bfs到最后我能写成(p1,p1)服了明明是(p1,p2),最重要的是,找了两天也没找到,以后一定强加联系



#include <iostream>

#include <stdio.h>
#include <string.h>
#include <queue>
#define maxn 1000 + 10




using namespace std;


int final;
int vis[maxn][maxn];
int map[maxn][maxn];
int s[maxn][maxn];
int m,n;


int move[4][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}};


struct point
{
    int x,y;
};


bool check(point a)
{
    if( a.x >= 1 && a.x <= n && a.y >= 1 && a.y <= m && vis[a.x][a.y] == 0 && map[a.x][a.y] <= final)
        return true;
    return false;
}




int bfs(int x,int y)
{
    queue<point> que;
    point now, temp;
    int count = 1;
    now.x = x;
    now.y = y;
    que.push(now);
    vis[x][y] = 1;
    s[x][y] = 1;


    while(!que.empty())
    {
        temp = que.front();
        que.pop();
      if(s[temp.x][temp.y] == 1)
       {


            for( int i = 0; i < 4; i++)
            {
                now.x = temp.x + move[i][0];
                now.y = temp.y + move[i][1];
                if(check(now))
                {
                      que.push(now);
                      vis[now.x][now.y] = 1;
                      count++;
                      s[now.x][now.y] = 1;
                }
           }
        }
    }
    return count;
}




int main()
{
   int  p1,p2;
   while(scanf("%d%d%d%d", &n, &m, &p1, &p2) != EOF)
   {
       memset(vis,0,sizeof(vis));
       memset(s,0,sizeof(s));
       
       for( int i = 1; i<= n; i++)
        for( int j = 1; j <= m ;j++)
            scanf("%d",&map[i][j]);
        final = map[p1][p2];
        printf("%d\n",bfs(p1,p2));


   }


}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值