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时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支 ...
随机推荐
- java导出excel表格
java导出excel表格: 1.导入jar包 <dependency> <groupId>org.apache.poi</groupId> <artifac ...
- Java 字符编码归纳总结
String newStr = new String(oldStr.getBytes(), "UTF-8"); java中的String类是按照unicode进行编码的 ...
- 【POJ】【2699】The Maximum Number of Strong Kings
网络流/最大流/二分or贪心 题目大意:有n个队伍,两两之间有一场比赛,胜者得分+1,负者得分+0,问最多有几只队伍打败了所有得分比他高的队伍? 可以想到如果存在这样的“strong king”那么一 ...
- 委托、事件和Lambda
一.委托 delegate1.在.Net平台下,委托类型用来定义和响应应用程序中的回调.事实上,.Net委托类型是一个类型安全的对象,指向可以以后调用的其他方法,.Net委托是内置支持多路广播和异步方 ...
- 响应式设计Responsinator工具推荐
from:http://www.25xt.com/allcode/4066.html 原文推荐了5种,感觉有用的吧就这一种,所以收藏过来. Responsinator工具的好处Responsinato ...
- TGL站长关于常见问题的回复
问题地址: http://www.thegrouplet.com/thread-112923-1-1.html 问题: 网站配有太多的模板是否影响网站加载速度 月光答复: wp不需要删除其他的模板,不 ...
- 【转载】MySQL索引原理及慢查询优化
原文链接:美团点评技术团队:http://tech.meituan.com/mysql-index.html MySQL凭借着出色的性能.低廉的成本.丰富的资源,已经成为绝大多数互联网公司的首选关系型 ...
- .NET设计模式(10):装饰模式(Decorator Pattern)(转)
概述 在软件系统中,有时候我们会使用继承来扩展对象的功能,但是由于继承为类型引入的静态特质,使得这种扩展方式缺乏灵活性:并且随着子类的增多(扩展功能的增多),各种子类的组合(扩展功能的组合)会导致更多 ...
- Java对象初始化详解
在Java中,一个对象在可以被使用之前必须要被正确地初始化,这一点是Java规范规定的.本文试图对Java如何执行对象的初始化做一个详细深入地介绍(与对象初始化相同,类在被加载之后也是需要初始化的,本 ...
- 提高Python运行效率的六个窍门
曾灵敏 - MAY 18, 2015 Python是一门优秀的语言,它能让你在短时间内通过极少量代码就能完成许多操作.不仅如此,它还轻松支持多任务处理,比如多进程. 不喜欢Python的人经常会吐嘈P ...