timus 1033 Labyrinth(BFS)
Labyrinth
Memory limit: 64 MB
of the labyrinth has decided to start a new season with new wallpapers.
For this purpose they need a program to calculate the surface area of
the walls inside the labyrinth. This job is just for you!
≤ 33, you see, ‘3’ is a magic digit!). Some matrix cells contain a dot
character (‘.’) that denotes an empty square. Other cells contain a
diesis character (‘#’) that denotes a square filled by monolith block of
stone wall. All squares are of the same size 3×3 meters.
walls are constructed around the labyrinth (except for the upper left
and lower right corners, which are used as entrances) and on the cells
with a diesis character. No other walls are constructed. There always
will be a dot character at the upper left and lower right corner cells
of the input matrix.
task is to calculate the area of visible part of the walls inside the
labyrinth. In other words, the area of the walls' surface visible to a
visitor of the labyrinth. Note that there's no holes to look or to move
through between any two adjacent blocks of the wall. The blocks are
considered to be adjacent if they touch each other in any corner. See
picture for an example: visible walls inside the labyrinth are drawn
with bold lines. The height of all the walls is 3 meters.
Input
characters each. Each line describes one row of the labyrinth matrix.
In each line only dot and diesis characters will be used and each line
will be terminated with a new line character. There will be no spaces in
the input.
Output
Sample
input | output |
---|---|
5 |
198 |
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define inf 0x3f3f3f3f
#define mod 10000
typedef long long ll;
using namespace std;
const int N=;
const int M=;
int n,m,k,ans=,t,cnt;
int vis[N][N];
int d[][]={,,,,-,,,-};
char w[N][N];
struct man{
int x,y;
};
void bfs(int x,int y)
{
queue<man>q;
vis[x][y]=;
man s;s.x=x;s.y=y;
q.push(s);
while(!q.empty()){
man t=q.front();q.pop();
for(int i=;i<;i++){
int xx=t.x+d[i][];
int yy=t.y+d[i][];
if(xx<||xx>=n||yy<||yy>=n)ans++;
else if(w[xx][yy]=='#')ans++;
else if(!vis[xx][yy]){
man k;k.x=xx;k.y=yy;
q.push(k);
vis[xx][yy]=;
}
}
}
}
int main() {
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%s",w[i]);
}
bfs(,);
if(!vis[n-][n-])bfs(n-,n-);
printf("%d\n",(ans-)*);
return ;
}
timus 1033 Labyrinth(BFS)的更多相关文章
- URAL.1033 Labyrinth (DFS)
URAL.1033 Labyrinth (DFS) 题意分析 WA了好几发,其实是个简单地DFS.意外发现这个俄国OJ,然后发现ACRUSH把这个OJ刷穿了. 代码总览 #include <io ...
- Codeforces Round #354 (Div. 2) D. Theseus and labyrinth bfs
D. Theseus and labyrinth 题目连接: http://www.codeforces.com/contest/676/problem/D Description Theseus h ...
- URAL 1033 Labyrinth
E - Labyrinth Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submi ...
- Codeforces Round #516 (Div. 2)D. Labyrinth(BFS)
题目链接:http://codeforces.com/contest/1064/problem/D 题目大意:给你一个n*m的图,图中包含两种符号,'.'表示可以行走,'*'表示障碍物不能行走,规定最 ...
- cf1063B Labyrinth (bfs)
可以证明,如果我搜索的话,一个点最多只有两个最优状态:向左剩余步数最大时和向右剩余步数最大时 然后判一判,bfs就好了 dfs会T惨... #include<bits/stdc++.h> ...
- 1033. Labyrinth(dfs)
1033 简单dfs 有一点小小的坑 就是图可能不连通 所以要从左上和右下都搜一下 加起来 从讨论里看到的 讨论里看到一句好无奈的回复 “可不可以用中文呀...” #include <iostr ...
- codeforces 676D Theseus and labyrinth BFS搜索
分析:一个n*m的矩阵,每个格子有12个状态,每次按一次,每个格子转90度,所以整个矩阵只有4种状态,然后爆搜就好了 #include <cstdio> #include <iost ...
- Codeforces Round #516 (Div. 2) (A~E)
目录 Codeforces 1064 A.Make a triangle! B.Equations of Mathematical Magic C.Oh Those Palindromes D.Lab ...
- poj 1383 Labyrinth【迷宫bfs+树的直径】
Labyrinth Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 4004 Accepted: 1504 Descrip ...
随机推荐
- hdu 1034 (preprocess optimization, property of division to avoid if, decreasing order process) 分类: hdoj 2015-06-16 13:32 39人阅读 评论(0) 收藏
IMO, version 1 better than version 2, version 2 better than version 3. make some preprocess to make ...
- iOS开发之runtime运行时机制
最近参加三次面试都有被问到runtime,因为不太懂runtime我就只能支支吾吾的说点零碎.我真的好几次努力想看一看runtime的知识,因为知道理解它对理解OC代码内部变化有一定帮助,不过真心觉得 ...
- Block编程值得注意的那些事儿
[深入浅出Cocoa]Block编程值得注意的那些事儿 [深入浅出Cocoa]Block编程值得注意的那些事儿 罗朝辉 (http://www.cnblogs.com/kesalin/) 本文遵循 ...
- 链表(C++语言实现)
我使用的是严蔚敏的数据结构C语言版,很反感里面的全是伪代码,平常也没怎么敲代码,链表和顺序表是数据结构的第一个实验课程,顺序表还好,但是链表就有点困难了,因为里面涉及指针的运用.我对于指针并不是很精通 ...
- HDU 5253 最小生成树(kruskal)+ 并查集
题目链接 #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> ...
- css 时钟
(转自:http://www.cnblogs.com/Wenwang/archive/2011/09/21/2184102.html) <!DOCTYPE html> <html l ...
- ASP.NET获取客户端及服务器的信息
客户端信息: 1. 在ASP.NET中专用属性: 获取服务器电脑名:Page.Server.ManchineName 获取用户信息:Page.User 获取客户端电脑名:Page.Request.Us ...
- HttpHandler中无法使用Session(context.Session 为Null)
一.问题描述: 最近需要做一个对特定请求(.report)进行响应的接口,当然是使用实现IHttpHandler来进行处理,实现IHttpHandler接口就必须要实现它的两个方法,ProcessRe ...
- Inno_setup制作升级包必须面临的几个问题
Inno_setup制作升级包必须面临的几个问题 分类: c/c++/GamingAnyWhere JavaScript linux shell基础知识 2013-12-18 22:14 1496人阅 ...
- MVC - Code First Migration Command line
当开发MVC应用程序, 使用.NET Entity Framework的Code First model试, 若是需要将model层对象的改动更新进数据库, 需要使用Package Manager C ...