这题因为各种琐事耽耽搁搁做了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简单文件选择器代码。支持多卡,排序

    一个很简单的文件选择器对话框,支持双sd卡,当然前提是要有sd卡..并且实现了排序效果. 只有100多行的代码,基本的思路就是用listview显示目录下的所有子文件,再判断是文件还是目录. 利用Co ...

  2. GCC常用命令行一览表

    GCC常用命令行一览表 这些常用的 gcc/g++ 命令行参数,你都知道么?1. gcc -E source_file.c-E,只执行到预编译.直接输出预编译结果. 2. gcc -S source_ ...

  3. Codeforces Round #249 (Div. 2) D. Special Grid 枚举

    题目链接: http://codeforces.com/contest/435/problem/D D. Special Grid time limit per test:4 secondsmemor ...

  4. Dijkstra--POJ 2502 Subway(求出所有路径再求最短路径)

    题意: 你从家往学校赶,可以用步行和乘坐地铁这两种方式,步行速度为10km/h,乘坐地铁的速度为40KM/h.输入数据的第一行数据会给你起点和终点的x和y的坐标.然后会给你数目不超过200的双向地铁线 ...

  5. 【BZOJ】【1037】【ZJOI2008】生日聚会party

    DP orz iwtwiioi 这种题居然是DP……原来统计方案数是可以用动态规划来做的啊= =用一些变量来维护一些信息,保证方案可行性/合法性 人太弱实在是有些忧伤…… /************* ...

  6. 【BZOJ】【3171】【TJOI2013】循环格

    网络流/费用流 最后能走回出发点……说明全部是环= = 而二分图上的环说明什么呢……完备匹配 对于每个点,它都有四个可能的匹配点,且已知它已经(伪)匹配的一个点,那么我们于已知每条(伪)匹配边,我们连 ...

  7. NYOJ-214 单调递增子序列(二) AC 分类: NYOJ 2014-01-31 08:06 233人阅读 评论(0) 收藏

    #include<stdio.h> #include<string.h> int len, n, i, j; int d[100005], a[100005]; int bin ...

  8. CIFAR-10 Competition Winners: Interviews with Dr. Ben Graham, Phil Culliton, & Zygmunt Zając

    CIFAR-10 Competition Winners: Interviews with Dr. Ben Graham, Phil Culliton, & Zygmunt Zając Dr. ...

  9. 拆分Sql列中内容的拆分

    拆分Sql列中内容的拆分. /*按照符号分割字符串*/ create function [dbo].[m_split](@c varchar(2000),@split varchar(2)) retu ...

  10. BZOJ2463: [中山市选2009]谁能赢呢?

    感慨下汉堡的找水题能力… /************************************************************** Problem: 2463 User: zhu ...