水题一道却交了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. 安装ARM交叉编译器

    1.开发平台 虚拟机:VMware 12 操作系统:Ubuntu 14.04 64bit 2.准备ARM交叉编译工具包 编译uboot和linux kernel都需要ARM交叉工具链支持,这里使用Li ...

  2. Linux文件锁学习-flock, lockf, fcntl

    参考  linux中fcntl().lockf.flock的区别 这三个函数的作用都是给文件加锁,那它们有什么区别呢? 首先flock和fcntl是系统调用,而lockf是库函数.lockf实际上是f ...

  3. 如何让搜索引擎抓取AJAX内容? 转

    越来越多的网站,开始采用"单页面结构"(Single-page application). 整个网站只有一张网页,采用 Ajax 技术,根据用户的输入,加载不同的内容. 这种做法的 ...

  4. IOS开发-UI学习-UITextField的各种属性设置

    UITextField是IOS中非常常用的一个控件,用来接收用户输入信息,完成应用和用户的交互.它的主要属性设置如下: //初始化textfield并设置位置及大小 UITextField *text ...

  5. [Angular Tutorial] 5-Filtering Repeaters

    在上一步中,我们花了很大功夫来布局应用的基础,所以我们现在做点简单点的吧!我们将会添加一个全文本搜索框(没错,这很简单). ·我们的应用现在会有一个搜索框,注意页面中手机列表的改变取决于用户在搜索框键 ...

  6. eclipse中集成svn maven开发手册---maven编译打包

    使用eclipse中maven进行打包. 打好的包在相应的workspace下面会有一个release的文件夹,如图

  7. Python3基础 add() 向集合中加入新的元素

    镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...

  8. mybatis:"configuration" must match "(properties?,settings?,typeAliase.....

    在运行mybatis配置文件的时候,出现错误: mybatis:"configuration" must match "(properties?,settings?,ty ...

  9. php在客户端禁用cookie时让session不失效的解决方法

    cookie固然好,不过有些客户端浏览器会禁用cookie,这就会导致你所依赖cookies的程序会失效或出错,那么若真出现用户关闭cookies的情况,PHP应该如何再次使用session?方法还是 ...

  10. Xcache和memcache的比较

    Xcache 和 memcached 是两个不同层面的缓存,不存在可比性. Xcache 是 php 底层的缓存,它将PHP程式编译成字节码(byte code),再透过服务器上安装对应的程式来执行P ...