这题因为各种琐事耽耽搁搁做了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. Android:apk文件结构

    Android apk文件,即Android application package文件. 每个要安装到Android平台的应用都要被编译打包为一个单独的文件,后缀名为.apk,其中包含了应用的二进制 ...

  2. WinForm-利用Anchor和Dock属性缩放控件

    转自:http://www.cnblogs.com/tianzhiliang/articles/2144692.html 有一点让许多刚接触WinForms编程的开发者感到很棘手,就是在用户调整各种控 ...

  3. selenium IDE--录制和回放脚本

    1 selenium IDE--录制脚本 准备工作:firefox 浏览器安装了selenium IDE 插件 实例:打开百度搜索“软件测试” firefox浏览器打开网址:https://www.b ...

  4. SPOJ-SQRBR Square Brackets

    原题传送:http://www.spoj.pl/problems/SQRBR 动态规划. 设f[i][j]表示前i个位置在合法情况下缺少j个右括号的方案数. 转移方程为: f[i][j] = f[i- ...

  5. jquery cdn加速点

    新浪jquery cdn加速点: <script src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.js">< ...

  6. SpringMVC:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax;

    今天用SpringMVC做修改添加操作,之前的操作都实现了添加修改,但始终报com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have ...

  7. .Net 执行 Oracle SQL语句时, 中文变问号

      带中文的Sql语句在.Net调用时, 中文变问号(可使用 SQL Tracker工具跟踪)   问题:       服务器的字符集与客户端的字符集不一致. 解决方法: 1.  查看服务端的字符集: ...

  8. Sqli-labs less 61

    Less-61 此处对于id处理还是有点奇葩的,第一次遇到利用两层括号的.(可能我头发比较长,见识短了).形式和上述是一样的 payload: http://127.0.0.1/sqli-labs/L ...

  9. 下拉菜单得经典写法html5

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. jquery ajax post 传递数组 ,多checkbox 取值

    jquery ajax post 传递数组 ,多checkbox 取值 http://w8700569.iteye.com/blog/1954396 使用$.each(function(){});可以 ...