URAL.1033 Labyrinth (DFS)

题意分析

WA了好几发,其实是个简单地DFS。意外发现这个俄国OJ,然后发现ACRUSH把这个OJ刷穿了。

代码总览

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#define INF 0x3f3f3f3f
#define nmax 35
#define MEM(x) memset(x,0,sizeof(x))
using namespace std;
int spx[] = {0,1,0,-1};
int spy[] = {1,0,-1,0};
char mp[35][35];
bool visit[35][35];
int n,ans;
void dfs(int x,int y)
{
for(int i=0;i<4;i++){
int nx = x + spx[i];
int ny = y +spy[i];
if(!visit[nx][ny] && mp[nx][ny]=='.'){
visit[nx][ny] = true;
dfs(nx,ny);
}
else if(mp[nx][ny]=='#')
ans++;
}
} int main()
{
//freopen("in.txt","r",stdin);
while(scanf("%d",&n)!= EOF){
ans = 0;
memset(mp,'#',sizeof(mp));
for(int i=1;i<=n;i++){
scanf("%s",mp[i]+1);
mp[i][n+1] = '#'; }
visit[1][1] = true;
dfs(1,1);
if(!visit[n][n]){
visit[n][n] = true;
dfs(n,n);
}
printf("%d\n",(ans-4)*9);
}
return 0;
}

URAL.1033 Labyrinth (DFS)的更多相关文章

  1. URAL 1033 Labyrinth

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

  2. 1033. Labyrinth(dfs)

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

  3. timus 1033 Labyrinth(BFS)

    Labyrinth Time limit: 1.0 secondMemory limit: 64 MB Administration of the labyrinth has decided to s ...

  4. Educational Codeforces Round 5 - C. The Labyrinth (dfs联通块操作)

    题目链接:http://codeforces.com/contest/616/problem/C 题意就是 给你一个n行m列的图,让你求’*‘这个元素上下左右相连的连续的’.‘有多少(本身也算一个), ...

  5. URAL 1136 Parliament (DFS)

    题意 输入一棵树的后缀表达式(按左-右-中顺序访问),这棵树的每一个结点的数值都比它的左子树结点的数值大,而比它的右子树结点的数值小,要求输出其按右-左-中顺序访问的表达式.所有的数都为正整数,而且不 ...

  6. URAL题解一

    URAL题解一 URAL 1002 题目描述:一种记住手机号的方法就是将字母与数字对应,如图.这样就可以只记住一些单词,而不用记住数字.给出一个数字串和n个单词,用最少的单词数来代替数字串,输出对应的 ...

  7. 记忆化搜索(DP+DFS) URAL 1183 Brackets Sequence

    题目传送门 /* 记忆化搜索(DP+DFS):dp[i][j] 表示第i到第j个字符,最少要加多少个括号 dp[x][x] = 1 一定要加一个括号:dp[x][y] = 0, x > y; 当 ...

  8. URAL 1208 Legendary Teams Contest(DFS)

    Legendary Teams Contest Time limit: 1.0 secondMemory limit: 64 MB Nothing makes as old as years. A l ...

  9. URAL 1145—— Rope in the Labyrinth——————【求树的直径】

    Rope in the Labyrinth Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. PS 抠图和添加背景图

    1.打开需要抠的图--然后使用套索类工具,魔棒类工具,钢笔类工具均可选择需要扣的图片范围任何在Delete(如果抠反了可以进行反选Ctrl +shift+I) 2.然后把任一一张背景图直接拖到PS里面 ...

  2. 372. Delete Node in a Linked List【LintCode java】

    Description Implement an algorithm to delete a node in the middle of a singly linked list, given onl ...

  3. Mount qcow2 image

    1.Mount a qcow2 image qemu-nbd - QEMU Disk Network Block Device Server: Export QEMU disk image using ...

  4. 人脸识别 ArcFace Demo [Windows]

    Arcsoft ArcfaceDemo for Windows, VS2013 C++   使用虹软技术开发完成 使用步骤: 1.下载SDK包,32位Windows平台将五个SDK包里lib中的文件到 ...

  5. UVa 1585 - Score - ACM/ICPC Seoul 2005 解题报告 - C语言

    1.题目大意 给出一个由O和X组成的字符串(长度为80以内),每个O的得分为目前连续出现的O的数量,X得分为0,统计得分. 2.思路 实在说不出了,这题没过脑AC的.直接贴代码吧.=_= 3.代码 # ...

  6. 一:HDFS 用户指导

    1.hdfs的牛逼特性 Hadoop, including HDFS, is well suited for distributed storage and distributed processin ...

  7. 20170413B端业务访问故障排查思路

    现象: 1.全国用户电视端页面无法显示,刷不出版面. 2.后端服务无法打开,报错,504,502   显示服务器端业务故障超时. 3.其他业务也出现缓慢情况,并不严重. 排查: 1.系统服务排查,常规 ...

  8. C语言文件基本操作

    1.用文本方式储存‘1’,‘0’,‘2’存入文件,然后用二进制方式从文件开头读出一个short型数据,并验证结果是否正确 #include<stdio.h> #include<str ...

  9. 正确使用memset

    今天做了一道素数打表的题我在使用一个数组记录是否为素数的时候使用了memset,将数组里面的数都清为1,代表是素数,不是素数,就改成0,我在判断这一个数是否为素数是依据也是是0还是1,结果一直存在问题 ...

  10. iOS- <项目笔记>UI控件常见属性总结

    1.UIView // 如果userInteractionEnabled=NO,不能跟用户交互 @property(nonatomic,getter=isUserInteractionEnabled) ...