水题一道却交了4次QAQ,真是蒟蒻QAQ

CODE:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
struct node{
 int x,y,t;
}st,en;
queue<node> s;
#define maxn 1010
int a[maxn][maxn];
bool b[maxn][maxn];
int w[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int n,m;
char str[10000];
int main(){
 scanf("%d%d",&n,&m);
 for (int i=1;i<=n;i++){
  scanf("%s",str);
  for (int j=1;j<=m;j++){
   if (str[j-1]=='#') a[i][j]=1;
   else if (str[j-1]=='@') {st=(node){i,j,0};a[i][j]=1;}
   else if (str[j-1]=='=') en=(node){i,j,0};
   else  if (str[j-1]!='.')a[i][j]=str[j-1];
  }
 }
 s.push(st);
 for (int i=1;i<=n;i++) a[i][0]=a[i][m+1]=1;
 for (int i=1;i<=m;i++) a[0][i]=a[n+1][i]=1;
 while (!s.empty()){
  node u=s.front();
  if (u.x==en.x&&u.y==en.y) {printf("%d",u.t);return 0;}
  s.pop();
  for (int i=0;i<4;i++)
   if (a[u.x+w[i][0]][u.y+w[i][1]]!=1){
    if (a[u.x+w[i][0]][u.y+w[i][1]]>1){
     if (b[u.x+w[i][0]][u.y+w[i][1]]) continue;
     b[u.x+w[i][0]][u.y+w[i][1]]=1;
     for (int k=1;k<=n;k++)
      for (int j=1;j<=m;j++)
       if ( a[k][j]==a[u.x+w[i][0]][u.y+w[i][1]] &&(u.x+w[i][0]!=k||u.y+w[i][1]!=j) ) {s.push((node){k,j,u.t+1});}
    }else {
    a[u.x+w[i][0]][u.y+w[i][1]]=1;
    s.push((node){u.x+w[i][0],u.y+w[i][1],u.t+1});
    }
    }
 }
 return 0;
}

BZOJ 3299: [USACO2011 Open]Corn Maze玉米迷宫(BFS)的更多相关文章

  1. 3299: [USACO2011 Open]Corn Maze玉米迷宫

    3299: [USACO2011 Open]Corn Maze玉米迷宫 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 137  Solved: 59[ ...

  2. 【BZOJ】3299: [USACO2011 Open]Corn Maze玉米迷宫(bfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3299 映射一下传送门即可.. #include <cstdio> #include &l ...

  3. bzoj3299 [USACO2011 Open]Corn Maze玉米迷宫

    Description 今年秋天,约翰带着奶牛们去玩玉米迷宫.迷宫可分成NxM个格子,有些格子种了玉 米,种宥玉米的格子无法通行.  迷宫的四条边界上都是种了玉米的格子,其屮只有一个格子 没种,那就是 ...

  4. 【bzoj 3299】 [USACO2011 Open]Corn Maze玉米迷宫(最短路)

    就一个最短路,并且边长都是1,所以每个点只搜一次. /************************************************************** Problem: 3 ...

  5. P1825 [USACO11OPEN]玉米田迷宫Corn Maze

    题目描述 This past fall, Farmer John took the cows to visit a corn maze. But this wasn't just any corn m ...

  6. 洛谷——P1825 [USACO11OPEN]玉米田迷宫Corn Maze

    P1825 [USACO11OPEN]玉米田迷宫Corn Maze 题目描述 This past fall, Farmer John took the cows to visit a corn maz ...

  7. 洛谷—— P1825 [USACO11OPEN]玉米田迷宫Corn Maze

    https://www.luogu.org/problem/show?pid=1825 题目描述 This past fall, Farmer John took the cows to visit ...

  8. 洛谷 P1825 [USACO11OPEN]玉米田迷宫Corn Maze

    P1825 [USACO11OPEN]玉米田迷宫Corn Maze 题目描述 This past fall, Farmer John took the cows to visit a corn maz ...

  9. [USACO11OPEN]玉米田迷宫Corn Maze

    题目描述 This past fall, Farmer John took the cows to visit a corn maze. But this wasn't just any corn m ...

随机推荐

  1. php+jquery+ajax+json简单小例子

    直接贴代码: <html> <title>php+jquery+ajax+json简单小例子</title> <?php header("Conte ...

  2. Django之强大的Form功能

    转载: http://www.cnblogs.com/0820-zq/p/5807980.html Form Form的验证思路 前端:form表单 后台:创建form类,当请求到来时,先匹配,匹配出 ...

  3. Variation of e.touches, e.targetTouches and e.changedTouches

    We have the following lists: touches: A list of information for every finger currently touching the ...

  4. HBuilder开发App教程04-最难搞定的是mui

    前言 前几篇说到一些HBuilder开发app的基础教程, 现在来说一下HBuilder开发app的难点,或者说是上手的难点, 就是mui, 如果你没有研究mui就贸然的上手HBuilder,那你的开 ...

  5. HDU-5123-who is the best?

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5123 水题一个,直接hash: 代码 #include<stdio.h>#include& ...

  6. js原生设计模式——3简单工厂模式\js面向对象编程实例

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  7. 利用PHPCMS V9站群功能建立分站

    hosts文件就在C:\Windows\system32\drivers\etc\hosts下 用一套CMS软件系统,做多个网站,统一管理,用户可以互通,这就是所谓的站群功能.这对于运营和维护都能节省 ...

  8. C# 堆栈和堆 Heap & Stack

    首先堆栈和堆(托管堆)都在进程的虚拟内存中.(在32位处理器上每个进程的虚拟内存为4GB) 堆栈stack 堆栈中存储值类型. 堆栈实际上是向下填充,即由高内存地址指向低内存地址填充. 堆栈的工作方式 ...

  9. TCMalloc

    一. 原理 tcmalloc就是一个内存分配器,管理堆内存,主要影响malloc和free,用于降低频繁分配.释放内存造成的性能损耗,并且有效地控制内存碎片.glibc中的内存分配器是ptmalloc ...

  10. 微信小程序教程(第二篇)

    如何注册接入小程序及搭建开发环境 小程序接入流程 注册 主要分为注册邮箱与信息登记. 需要重新申请一个新的微信公众帐号,不能使用服务号.订阅号或企业号使用的公众帐号 (微信公众帐号分为四种类型:订阅号 ...