Labyrinth

Time limit: 1.0 second
Memory limit: 64 MB
Administration
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!
The labyrinth is represented by a matrix N×N (3 ≤ N
≤ 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.
The
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.
Your
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

The first line of the input contains the single number N. The next N lines contain N
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

Your program should print to the output a single integer — the exact value of the area of the wallpaper needed.

Sample

input output
5
.....
...##
..#..
..###
.....
198
Problem Author: Vladimir Pinaev
【分析】简单BFS,先从起点出发,遇到#边ans就++;存在不连通情况,所以要从终点再找一遍,最后减去两个角的四条边。

#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)的更多相关文章

  1. URAL.1033 Labyrinth (DFS)

    URAL.1033 Labyrinth (DFS) 题意分析 WA了好几发,其实是个简单地DFS.意外发现这个俄国OJ,然后发现ACRUSH把这个OJ刷穿了. 代码总览 #include <io ...

  2. 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 ...

  3. URAL 1033 Labyrinth

    E - Labyrinth Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submi ...

  4. Codeforces Round #516 (Div. 2)D. Labyrinth(BFS)

    题目链接:http://codeforces.com/contest/1064/problem/D 题目大意:给你一个n*m的图,图中包含两种符号,'.'表示可以行走,'*'表示障碍物不能行走,规定最 ...

  5. cf1063B Labyrinth (bfs)

    可以证明,如果我搜索的话,一个点最多只有两个最优状态:向左剩余步数最大时和向右剩余步数最大时 然后判一判,bfs就好了 dfs会T惨... #include<bits/stdc++.h> ...

  6. 1033. Labyrinth(dfs)

    1033 简单dfs 有一点小小的坑 就是图可能不连通 所以要从左上和右下都搜一下 加起来 从讨论里看到的 讨论里看到一句好无奈的回复 “可不可以用中文呀...” #include <iostr ...

  7. codeforces 676D Theseus and labyrinth BFS搜索

    分析:一个n*m的矩阵,每个格子有12个状态,每次按一次,每个格子转90度,所以整个矩阵只有4种状态,然后爆搜就好了 #include <cstdio> #include <iost ...

  8. Codeforces Round #516 (Div. 2) (A~E)

    目录 Codeforces 1064 A.Make a triangle! B.Equations of Mathematical Magic C.Oh Those Palindromes D.Lab ...

  9. poj 1383 Labyrinth【迷宫bfs+树的直径】

    Labyrinth Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 4004   Accepted: 1504 Descrip ...

随机推荐

  1. 创建条形码图像易用的控制字符编码功能的条形码控件Native Crystal Reports Barcode Generator

    Native Crystal Reports Barcode Generator是一个对象,它可以很容易地被嵌入到一个Crystal Report中用于创建条形码图像.一旦此条形码被安装在一个报表中, ...

  2. iphone获取当前运行进程列表

    通过调用 sys/sysctl.h 读取系统内核获取进程列表 . 代码悦德财富:https://yuedecaifu.com 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 ...

  3. Power Point已经检测到你的显卡可能无法正确配置

    Microsoft PowerPoint打开ppt时提示信息 PowerPoint已检测到你的显卡可能无法正确配置最佳的幻灯片播放体验(“Power Point has detected that y ...

  4. 程序中double类型的数输出为什么要用lf

    在c89和c++中double的输入和输入输出都用%lf 在c99中,double的输出必须用%f,而输入要用%lf oIER一般使用c++,所以输出直接%lf即可.

  5. (转)面向移动设备的HTML5开发框架

    (原)http://www.cnblogs.com/itech/archive/2013/07/27/3220352.html 面向移动设备的HTML5开发框架   转自:http://blogrea ...

  6. (转)innerHTML、innerText和outerHTML、outerText的区别

    原文:http://walsh.iteye.com/blog/261966 innerHTML.innerText和outerHTML.outerText的区别          博客分类: CSS/ ...

  7. hdu 2055

    PS:上课的时候敲的..这道题简单..一次AC,不多说了.. 代码: #include "stdio.h"int main(){ int i,n,y; char x,a[26],b ...

  8. MouseJack:利用15美元的工具和15行代码控制无线鼠标和键盘

    Bastille的研究团队发现了一种针对蓝牙键盘鼠标的攻击,攻击者可以利用漏洞控制你的电脑操作.研究团队将此攻击命名为MouseJack. 七大厂商皆中招 软件工程师马克纽林说:“利用假冒的无线电脑鼠 ...

  9. CRM客户关系管理系统 ——客户联系人添加(十五)

    需求描述: 1.业务员自己可以查看属于自己的客户信息 2.客服部经理可以查看查看所有客户信息 3.其他人员不得查看客户信息 效果截图:  

  10. 4、SQL基础整理(规范函数)

    规范函数: 绝对值 select abs(-5) print abs(-5) 表中取绝对值的方法: select code,name,abs(chinese)as yuwen from xueshen ...