这题因为各种琐事耽耽搁搁做了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. C#委托详解(2):实现方式大全

    本系列文章将详细探讨C#中的委托,列举其主要的实现方式,并分析其在设计层面和编码层面带来的好处,最后会讨论其安全性和执行效率等. 接上篇(C#委托详解(1):什么是委托)介绍完什么是委托之后,来看看C ...

  2. Careercup - Microsoft面试题 - 5943729928011776

    2014-05-10 21:56 题目链接 原题: Suppose you get number of unique users every second from bing For eg, ,,,, ...

  3. 【BZOJ】【4027】【HEOI2015】兔子与樱花

    贪心 树上贪心问题……跟APIO2015练习赛的C很像啊…… 我的思路是:从叶子向上考虑,令a[x]表示x这个节点上樱花数量与儿子个数的和(即对于任意的x,都有$a[x]\leq m$)每次从儿子的a ...

  4. 【BZOJ】【1031】【JSOI2007】字符加密Cipher

    后缀数组 当年感觉好神的题现在好像变水了…… 题意其实有点蛋疼……一开始没看懂<_< 将原串复制一遍接在后面,用后缀数组求一下SA,那么SA<n的就是所找到的那n个字符串,然后把它们 ...

  5. 堆(heap)和栈(stack)的区别

    转: 一.预备知识―程序的内存分配 一个由c/C++编译的程序占用的内存分为以下几个部分 1.栈区(stack)― 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等.其操作方式类似于数据结构中 ...

  6. Search API 官方文档 可以用了查看自己的app

    Search API October 24, 2012 - HTTPS is now supported for Search and Lookup requests. Please update y ...

  7. nodeJs 初探 ~

    今天晚上,开始时间了一下nodejs,跟着 Node入门 一步步的往下走.对node开发也有了初步的了解. 期间没有碰到什么问题,只有在最后的时候,碰到了几个问题.在这里记录一下: 1 . cross ...

  8. 如何做好一名DBA【转】

    我一直有一个观点:程序是暂时的,而数据是永恒的.所以我一直都认为数据的重要性在很多企业中都远远高于应用程序,在多年的工作实践中努力做好DBA的工作.而要做好一名DBA,必须要清楚作为一名DBA的职责. ...

  9. 如何开发一个自己的 RubyGem?

    「如何测试你的 RubyGem?」的前导文章 什么是 RubyGem RubyGem 是 Ruby 语言的标准源码打包格式. 大家一直都在用gem这个命令,但是很少有人知道这个东西是怎么来的,这里我从 ...

  10. Server Library [Apache Tomcat v6.0](unbound)服务未绑定解决办法

    (1) 单击File按钮---钩选Show AllWizard——>选择Server——>单击Next (2)Add Library    选择 WTP Server Runtime(My ...