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时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支 ...
随机推荐
- Kibana4学习<三>
discover 功能 Discover 标签页用于交互式探索你的数据.你可以访问到匹配得上你选择的索引模式的每个索引的每条记录.你可以提交搜索请求,过滤搜索结果,然后查看文档数据.你还可以看到匹配搜 ...
- Careercup - Microsoft面试题 - 5943729928011776
2014-05-10 21:56 题目链接 原题: Suppose you get number of unique users every second from bing For eg, ,,,, ...
- Careercup - Google面试题 - 4877486110277632
2014-05-08 05:16 题目链接 原题: Given a circle with N defined points and a point M outside the circle, fin ...
- 如何在Android模拟器上安装apk文件
1.运行SDK Manager,选择模拟器,并运行模拟器 SDK Manager应用 2.将需要安装的apk文件复制到platform-tools目录下(默认在:D:\tools\android\ad ...
- [转载]char * 和char []的区别---之第二篇
原文地址:http://blog.sina.com.cn/s/blog_74a4593801019keb.html main() { char *p="abc123ABC";//c ...
- 【BZOJ】【3166】【HEOI2013】Alo
可持久化Trie+set Orz zyf…… 搞区间中次大值不好搞,那么我们就反过来,找一个数,然后看它在哪些区间里是次大值…… (然而事实上我们并不用真的把这个区间具体是什么找见,只要知道它可以跟哪 ...
- log4j 配置实例
1. http://hehongwei44.iteye.com/blog/1494999 2. http://maymay.iteye.com/blog/1275432 #log4j.rootLogg ...
- 二分图匹配(KM算法)n^3 分类: ACM TYPE 2014-10-01 21:46 98人阅读 评论(0) 收藏
#include <iostream> #include<cstring> #include<cstdio> #include<cmath> const ...
- linux install
http://www.ubuntu.org.cn/index_kylin 先在官网下个Ubuntu 是个iso 然后下个UltraISO 是个软件 插好空u盘 打开软件 在菜单栏上 点击 文件-&g ...
- windows phone MVVM开发心得第一天
之前刚刚学了asp.net网站的三层架构,为其中的优点着迷,可惜寒假本来决定学下MVC的计划泡汤了,刚开学,学了下windows phone 的MVVM模式的开发,在此留下点心得和脚印,第一天只是学了 ...