URAL.1033 Labyrinth (DFS)
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)的更多相关文章
- URAL 1033 Labyrinth
E - Labyrinth Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submi ...
- 1033. Labyrinth(dfs)
1033 简单dfs 有一点小小的坑 就是图可能不连通 所以要从左上和右下都搜一下 加起来 从讨论里看到的 讨论里看到一句好无奈的回复 “可不可以用中文呀...” #include <iostr ...
- timus 1033 Labyrinth(BFS)
Labyrinth Time limit: 1.0 secondMemory limit: 64 MB Administration of the labyrinth has decided to s ...
- Educational Codeforces Round 5 - C. The Labyrinth (dfs联通块操作)
题目链接:http://codeforces.com/contest/616/problem/C 题意就是 给你一个n行m列的图,让你求’*‘这个元素上下左右相连的连续的’.‘有多少(本身也算一个), ...
- URAL 1136 Parliament (DFS)
题意 输入一棵树的后缀表达式(按左-右-中顺序访问),这棵树的每一个结点的数值都比它的左子树结点的数值大,而比它的右子树结点的数值小,要求输出其按右-左-中顺序访问的表达式.所有的数都为正整数,而且不 ...
- URAL题解一
URAL题解一 URAL 1002 题目描述:一种记住手机号的方法就是将字母与数字对应,如图.这样就可以只记住一些单词,而不用记住数字.给出一个数字串和n个单词,用最少的单词数来代替数字串,输出对应的 ...
- 记忆化搜索(DP+DFS) URAL 1183 Brackets Sequence
题目传送门 /* 记忆化搜索(DP+DFS):dp[i][j] 表示第i到第j个字符,最少要加多少个括号 dp[x][x] = 1 一定要加一个括号:dp[x][y] = 0, x > y; 当 ...
- 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 ...
- URAL 1145—— Rope in the Labyrinth——————【求树的直径】
Rope in the Labyrinth Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- Selenium自动化测试第二天(下)
如有任何学习问题,可以添加作者微信:lockingfree 目录 Selenium自动化测试基础 Selenium自动化测试第一天(上) Selenium自动化测试第一天(下) Selenium自动化 ...
- Android intel X86 图像渲染
最近几天有个项目需要在intel 芯片的系统上集成我们的视频通话软件.之前只是在ARM平台上使用,对于intel 没测试过,直接运行apk后,本端渲染的图像出错,渲染出的图像很像I420被作为RGB5 ...
- 完整的正则表达式知识汇总(Python知识不断更新)
## 大纲: ## 一.正则概述 1.正则是什么 正则就是一套规则,或者语法 2.正则的作用 让我们判断是否符合我们的的规则,或者根据规则找到符合规则的数据 3.使用场景 可以用正则判断我们输入的邮箱 ...
- 227. Mock Hanoi Tower by Stacks【LintCode java】
Description In the classic problem of Towers of Hanoi, you have 3 towers and N disks of different si ...
- Python对文本文件逐行扫描,将含有关键字的行存放到另一文件
#逐行统计关键字行数,并将关键字所在行存放在新的文件中 keyword = "INFO" b = open("C:\\Users\\xxx\\Documents\\new ...
- 使用eclipse创建maven项目出现的一个问题
错误信息 This error occurs when you employ a plugin that Maven could not download. Possible causes for t ...
- python 智能合约日志操作
from __future__ import unicode_literals import json from time import sleep, time # 中文编码 def encode_s ...
- “Hello world!”团队第二周贡献分规则+贡献分数分配结果
一.贡献规则制定: (1)基础分:9 , 9 , 8 , 7 , 7 , 7 , 6(按在本次编程中承担模块的重要度制定,某一模块重要度的认定通过组内开会讨论决定) (2)会议分:每人没出勤一次会议记 ...
- 福大软工1816 · 第五次作业 - 结对作业2_map与unordered map的比较测试
测试代码: #include <iostream> using namespace std; #include <string> #include <windows.h& ...
- C#中委托的发展与匿名函数
匿名函数(C# 编程指南) 匿名函数是一个“内联”语句或表达式,可在需要委托类型的任何地方使用. 可以使用匿名函数来初始化命名委托,或传递命名委托(而不是命名委托类型)作为方法参数. 共有两种匿名函数 ...