USACO Section 2.4: Overfencing
这题因为各种琐事耽耽搁搁做了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的更多相关文章
- 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&& ...
- 【USACO 2.4】Overfencing(bfs最短路)
H行W列的迷宫,用2*H+1行的字符串表示,每行最多有2*W+1个字符,省略每行后面的空格.迷宫的边界上有且仅有两个出口,求每个点出发到出口的最短路. +-+-+-+-+-+ | | +-+ +-+ ...
- USACO Section 3.3: Riding the Fences
典型的找欧拉路径的题.先贴下USACO上找欧拉路径的法子: Pick a starting node and recurse on that node. At each step: If the no ...
- USACO Section 3.3 Camlot(BFS)
BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...
- [IOI1996] USACO Section 5.3 Network of Schools(强连通分量)
nocow上的题解很好. http://www.nocow.cn/index.php/USACO/schlnet 如何求强连通分量呢?对于此题,可以直接先用floyd,然后再判断. --------- ...
- 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 ...
- USACO Section 1.3 Prime Cryptarithm 解题报告
题目 题目描述 牛式的定义,我们首先需要看下面这个算式结构: * * * x * * ------- * * * <-- partial product 1 * * * <-- parti ...
- USACO Section 1.1 Your Ride Is Here 解题报告
题目 问题描述 将字符串转变为数字,字母A对应的值为1,依次对应,字母Z对应的值为26.现在有一个字符串,将其中的每个字符转变为数字之后进行累乘,最终的结果对47求余数. 题目给你两个字符串,其中的字 ...
- USACO Section 1.1-1 Your Ride Is Here
USACO 1.1-1 Your Ride Is Here 你的飞碟在这儿 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支 ...
随机推荐
- hibernate3连oracle的各种坑。。
坑一:驱动错误导致sql查询不了,升级驱动到最新版即可 2.通过构造函数封装数据时,如果报错无法实例化并且不是因为字段不对应导致的,可以试试把float改为Float之类的包装类
- Unity的物理引擎是如何实现碰撞的呢?
物理引擎不允许两个碰撞器重叠,当两个或多个物体碰撞时,Unity会根 据他们的旋转速度计算碰撞效果.计算主要根据物体的碰撞器是静止的还 是动态的.物体是不移动的,例如,墙,地面,院子里的喷池等.动态物 ...
- Google Guava学习笔记——简介
Google Guava是什么东西?首先要追溯到2007年的“Google Collections Library”项目,它提供对Java 集合操作的工具类.后来Guava被进化为Java程序员开发必 ...
- 浅谈自我对git的初步认识
本学期我们新增了一门课程,那就是软件工程,不知道为什么,感觉有种莫名的高大上.哈哈!难道是这个名称太抽象了吗?这个问题我感觉到后来肯定就明白了. 第一次博客,感觉好紧张哦,嘿嘿!老师让我们谈谈对git ...
- httpclient模拟浏览器get\post
一般的情况下我们都是使用IE或者Navigator浏览器来访问一个WEB服务器,用来浏览页面查看信息或者提交一些数据等等.所访问的这些页面有的仅 仅是一些普通的页面,有的需要用户登录后方可使用,或者需 ...
- 简述负载均衡&CDN技术
曾经见到知乎上有人问“为什么像facebook这类的网站需要上千个工程师维护?”,下面的回答多种多样,但总结起来就是:一个高性能的web系统需要从无数个角度去考虑他,大到服务器的布局,小到软件中某个文 ...
- add some template for ec-final
二维rmq 离线 init O( n*n*logn*logn ) query O(1) http://www.cnblogs.com/kuangbin/p/3227420.html 求1-n有多少个 ...
- STMPClient 发送邮件显示 不允许使用邮件名称.
在.net 2.0,3.5, 针对某些邮箱(还不清楚是什么样的邮件) , 使用微软自带的DLL发送邮件会提示不允许使用邮件名称 .... 使用Jmail可以发送. 解决方案: 1. ...
- Windows Live Writer安装失败错误解决方案
初次使用博客园.看到官方推荐Windows Live Writer来写作博客.看着也不错.可以离线写作.不用担心浏览器突然卡卡卡,未响应的危险. Windows Live Writer是博客园推荐博客 ...
- HDOJ 1062 Text Reverse
Text Reverse Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...