这题因为各种琐事耽耽搁搁做了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. 【Convert Sorted List to Binary Search Tree】cpp

    题目: Given a singly linked list where elements are sorted in ascending order, convert it to a height ...

  2. 使用第三方工具覆写Object中方法

    我们在实际开发中,经常需要覆写Object中的equals,hashcode,toString方法,其实编写这些代码并不是很难,但很枯燥和乏味. 下面推荐Google的Guava jar包来覆写上面的 ...

  3. Codeforces Round #353 (Div. 2) E. Trains and Statistic 线段树+dp

    题目链接: http://www.codeforces.com/contest/675/problem/E 题意: 对于第i个站,它与i+1到a[i]的站有路相连,先在求所有站点i到站点j的最短距离之 ...

  4. 在linux中使用phpize安装php扩展模块

    介绍:linux系统中,php安装成功后,在bin目录下会生成一个名叫phpize的可执行脚本,这个脚本的用途是动态安装php扩展模块.使用phpize脚本安装php扩展模块的好处:在安装php时没有 ...

  5. 制作一个可以给team所有成员用的开发者证书

    1. 将证书的private key导出一个.p12的文件给别人 2. 从apple developer网站下载证书对应的provisioning profile 待优化

  6. 常用的Python字符串常量

    下面是一些常用的Python字符串常量string.digits:包含0-9的字符串string.letters:包含所有大小写字母的字符串 string.lowercase:所有小写字母string ...

  7. AngularJs学习笔记--directive

    原版地址:http://code.angularjs.org/1.0.2/docs/guide/directive Directive是教HTML玩一些新把戏的途径.在DOM编译期间,directiv ...

  8. 解决Ubuntu下内存不足---作为Slave的虚拟机

    1)在虚拟机上安装了Ubuntu桌面版作为DataNode,由于物理机内存的限制只是分了1G的内存给虚拟机,使用bin/start-all.sh启动了hadoop之后,Slave的资源使用情况如下图所 ...

  9. 【译】C++工程师需要掌握的10个C++11特性

    原文标题:Ten C++11 Features Every C++ Developer Should Use 原文作者:Marius Bancila 原文地址:codeproject 备注:非直译,带 ...

  10. Java中List、Set和Map的区别--转载

    List按对象进入的顺序保存对象,不做排序或编辑操作.Set对每个对象只接受一次,并使用自己内部的排序方法(通常,你只关心某个元素是否属于Set,而不关心它的顺序--否则应该使用List).Map同样 ...