水题一道却交了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. IOS开发中UIAlertController(警告框)的使用

    步骤一.初始化: UIAlertController * inputname = [UIAlertController alertControllerWithTitle:@"未输入账户&qu ...

  2. leetcode day8

    [83] Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such that ...

  3. UVa 10814 - Simplifying Fractions

    题目大意:给一个分数,对其进行化简.因为分子.分母最大为1030,所以用要用大数. import java.io.*; import java.util.*; import java.math.*; ...

  4. centos 单独安装nginx

    安装包下载网址: http://nginx.org/en/download.html 进入Linux文件夹执行 wget http://nginx.org/download/nginx-1.8.0.t ...

  5. Google Chrome调试js代码

    你 是怎么调试 JavaScript 程序的?最原始的方法是用 alert() 在页面上打印内容,稍微改进一点的方法是用 console.log() 在 JavaScript 控制台上输出内容.嗯~, ...

  6. Xtrabackup构建MySQL主从环境

    环境:HE3主库,HE1从库 HE1:192.168.1.248 HE3:192.168.1.250 从库my.cnf加入以下参数并重启数据库: read_only=1 log_slave_updat ...

  7. 解决xtrabackup command not found no mysqld group 问题

    现象:手动执行xtrabackup没问题,环境变量检查过也没问题.放到执行计划中 会报错: sh: xtrabackup_56: command not found innobackupex: Err ...

  8. ThinkPHP--IS_AJAX

    增加IS_GET,IS_POST,IS_PUT,IS_DELETE,IS_AJAX常量,方便除控制器外的地方判断方法,Action类的isGet isPost等方法暂时保留,但不建议使用.

  9. 多线程和多进程的区别(C++)

    很想写点关于多进程和多线程的东西,我确实很爱他们.但是每每想动手写点关于他们的东西,却总是求全心理作祟,始终动不了手. 今天终于下了决心,写点东西,以后可以再修修补补也无妨. 一.为何需要多进程(或者 ...

  10. Android 创建Library Project(库项目)与引用操作

    由于在开发过程,为了实现未曾了解的某种效果与特定功能,而求助于网上优秀的开源项目,在使用过程中发现引用开源的Library Project(库项目),的确可以解决很多问题,而且也给出了一种思路,好的软 ...