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 ...
随机推荐
- SPOJ COT2 树上找路径上不同值的个数
题目大意 给出多个询问u , v , 求出u-v路径上点权值不同的个数 开始做的是COT1,用主席树写过了,理解起来不难 很高兴的跑去做第二道,完全跟普通数组区间求k个不同有很大区别,完全没思路 膜拜 ...
- MongoDB 查询 (转) 仅限于C++开发
1.find MongoDB使用find来进行查询.查询就是返回一个集合中文档的子集,子集合的范围从0个文档到整个集合.find的第一个参数 决定了要返回哪些文档.其形式也是一个文档,说明要查询的细节 ...
- 2013年国庆节前51Aspx源码发布详情
Sky软件公司网站修正版源码 2013-9-30 [VS2010]源码描述:针对Sky软件公司网站源码进行修正.修改ckeditor引用问题,发布样式错误问题.vs2010直接编译.发布成功. 网站 ...
- table td的宽度详解
前言:一直总觉得td的宽度好难驾驭,但万事万物总是有规律的.就像亮剑说的:不用因为怕八路就敬而远之,应该靠上去,熟悉他们,了解他们. 正文: Table只有Table的宽度是可 ...
- JS 基于面向对象的 轮播图2
<script> // 函数不能重名, --> 子函数 // is defined function --> 函数名是否写错了 function AutoTab(id) { T ...
- hdu 2085
PS:递推题.. a[n]=a[n-1]*3+2*b[n-1] b[n]=a[n-1]+b[n-1] 代码: #include "stdio.h" ]; ]; int main ...
- UILabel自适应宽度的函数详解
之前用Text Kit写Reader的时候,在分页时要计算一段文本的尺寸大小,之前使用了NSString类的sizeWithFont:constrainedToSize:lineBreakMode:方 ...
- BZOJ 3782 上学路线
首先这个题需要dp.dp[i]=C(x[i]+y[i],x[i])-Σdp[j]*C(x[i]-x[j]+y[i]-y[j],x[i]-x[j])(x[i]>=x[j],y[i]>=y[j ...
- IOS 作业项目(2) 画图(保存,撤销,笔粗细设定功能)
先上效果图
- 破解 AD_CM#3
系统 : Windows xp 程序 : AD_CM#3 程序下载地址 :http://pan.baidu.com/s/1skwXPVn 要求 : 编写注册机 使用工具 :IDA & OD 可 ...