这题因为各种琐事耽耽搁搁做了2天,也出了挺多错误,最后出了一个结论:像这种有对neighbor有通路的图形用一个4个位表示4个方向的int进行位运算比较靠谱。

 /*
 ID: yingzho1
 LANG: C++
 TASK: maze1
 */
 #include <iostream>
 #include <fstream>
 #include <string>
 #include <map>
 #include <vector>
 #include <set>
 #include <algorithm>
 #include <stdio.h>
 #include <queue>
 #include <cstring>
 #include <cmath>
 #include <list>

 using namespace std;

 ifstream fin("maze1.in");
 ofstream fout("maze1.out");

 int W, H;
 ];

 struct node {
     int x, y;
     int neigh;
     int dis;
     node(int a, int b, int c, int d) : x(a), y(b), neigh(c), dis(d) { }
     node() : x(), y(), neigh(), dis() { }
 } maps[][];

 int dfs(node source) {
     ][] = {{-, }, {, }, {, -}, {, }};
     queue<node> S, T;
     S.push(source);
     ;
     vector<vector<, vector<));
     visit[source.x][source.y] = true;
     while (!S.empty()) {
         while (!S.empty()) {
             node tmp = S.front();
             S.pop();
             ; i < ; i++) {
                  == ) {
                     ];
                     ];
                      || xx > H || yy <=  || yy > W) continue;
                     if (!visit[xx][yy]) {
                         T.push(maps[xx][yy]);
                         maps[xx][yy].dis = min(maps[xx][yy].dis, account+);
                         visit[xx][yy] = true;
                     }
                 }
             }
         }
         if (!T.empty()) account++;
         swap(S, T);
     }
     return account;
 }

 int main()
 {
     fin >> W >> H;
     string tmp;
     vector<node> exits;
     getline(fin, tmp);
     ; i < *H+; i++) {
         getline(fin, board[i]);
         *W+) board[i] += *W+-board[i].size(), ' ');
     }

     ; i <= H; i++) {
         ; j <= W; j++) {
             maps[i][j].x = i, maps[i][j].y = j;
             *i--][*j-] != '-') {
                 maps[i][j].neigh |= ; //N 0001
                 ) exits.push_back(maps[i][j]);
             }
             *i-+][*j-] != '-') {
                 maps[i][j].neigh |= ; // S 0010
                 if (i == H) exits.push_back(maps[i][j]);
             }
             *i-][*j--] != '|') {
                 maps[i][j].neigh |= ; // W 0100
                 ) exits.push_back(maps[i][j]);
             }
             *i-][*j-+] != '|') {
                 maps[i][j].neigh |= ; // E 1000
                 if (j == W) exits.push_back(maps[i][j]);
             }
         }
     }
     maps[exits[].x][exits[].y].dis = , maps[exits[].x][exits[].y].dis = ;
     dfs(maps[exits[].x][exits[].y]);
     dfs(maps[exits[].x][exits[].y]);
     ;
     ; i <= H; i++) {
         ; j <= W; j++) {
             maxdis = max(maxdis, maps[i][j].dis);
         }
     }
     fout << maxdis << endl;

     ;
 }

USACO Section 2.4: Overfencing的更多相关文章

  1. USACO Section 1.3 题解 (洛谷OJ P1209 P1444 P3650 P2693)

    usaco ch1.4 sort(d , d + c, [](int a, int b) -> bool { return a > b; }); 生成与过滤 generator&& ...

  2. 【USACO 2.4】Overfencing(bfs最短路)

    H行W列的迷宫,用2*H+1行的字符串表示,每行最多有2*W+1个字符,省略每行后面的空格.迷宫的边界上有且仅有两个出口,求每个点出发到出口的最短路. +-+-+-+-+-+ | | +-+ +-+ ...

  3. USACO Section 3.3: Riding the Fences

    典型的找欧拉路径的题.先贴下USACO上找欧拉路径的法子: Pick a starting node and recurse on that node. At each step: If the no ...

  4. USACO Section 3.3 Camlot(BFS)

    BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...

  5. [IOI1996] USACO Section 5.3 Network of Schools(强连通分量)

    nocow上的题解很好. http://www.nocow.cn/index.php/USACO/schlnet 如何求强连通分量呢?对于此题,可以直接先用floyd,然后再判断. --------- ...

  6. USACO Section 5.3 Big Barn(dp)

    USACO前面好像有类似的题目..dp(i,j)=min(dp(i+1,j),dp(i+1,j+1),dp(i,j+1))+1  (坐标(i,j)处无tree;有tree自然dp(i,j)=0) .d ...

  7. USACO Section 1.3 Prime Cryptarithm 解题报告

    题目 题目描述 牛式的定义,我们首先需要看下面这个算式结构: * * * x * * ------- * * * <-- partial product 1 * * * <-- parti ...

  8. USACO Section 1.1 Your Ride Is Here 解题报告

    题目 问题描述 将字符串转变为数字,字母A对应的值为1,依次对应,字母Z对应的值为26.现在有一个字符串,将其中的每个字符转变为数字之后进行累乘,最终的结果对47求余数. 题目给你两个字符串,其中的字 ...

  9. USACO Section 1.1-1 Your Ride Is Here

    USACO 1.1-1 Your Ride Is Here 你的飞碟在这儿 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支 ...

随机推荐

  1. LNMP系列网站零基础开发记录(一)

    [目录] 扯淡吹逼之开发前奏 Django 开发环境搭建及配置 web 页面开发 Django app开发 Django 站点管理 Python 简易爬虫开发 Nginx&uWSGI 服务器配 ...

  2. Mybatis代码调试问题总结(一)

    问题: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):   原因排查: 1.检查map ...

  3. java web项目,java类中获得WEB-INF路径

    private static String getWebInfPath() { URL url = 当前类.class.getProtectionDomain().getCodeSource().ge ...

  4. [百度空间] [原]android下的各种坑

    一堆so文件安装不正确: apk里面都是全的, 但是安装完后/data/data/$pkg/lib下面就没有 google了好长时间没有结果.最后发现是因为没库有加lib前缀(当时想了一下觉得不加更好 ...

  5. 研究AVCaptureDevice

    一.Apple Resource 1. wwdc 2014: Camera Caputre: Manual Controls 2. Exaple code: AVCam&AVCamManul ...

  6. Codeforces Round #268 (Div. 2)

    补题解: E:只会第四种解法:也只看懂了这一种. PS:F[X+10^18]=F[X]+1;F[X]表示X的数字之和; 假设X,F[10^18+X]+F[10^18+X-1]+......F[10^1 ...

  7. mongodb维护常用命令

    一,用户操作:1. #进入数据库adminuse admin2. #增加或修改用户密码db.addUser('name','pwd')3. #查看用户列表db.system.users.find()4 ...

  8. Linuxshell脚本之if条件判断

    IF条件判断 .基本语法: if [ command ]; then 符合该条件执行的语句 fi .扩展语法: if [ command ];then 符合该条件执行的语句 elif [ comman ...

  9. PHP event 事件机制

    PHP event 事件机制   <?php /* * PHP 事件机制 */ class baseClass{ private $_e; public function __set($name ...

  10. Jsp helloWorld

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEnco ...