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 ...
 
随机推荐
- cf#516B. Equations of Mathematical Magic(二进制,位运算)
			
https://blog.csdn.net/zfq17796515982/article/details/83051495 题意:解方程:a-(a^x)-x=0 给出a的值,要求计算解(非负)的个数 ...
 - Monkey用真机做测试的步骤
			
1 必备条件 1) 手机需要先获取root权限: 2) 手机和电脑相连(电脑可以访问手机里面的文件) 2 操作步骤 1) 使用adb devices 命令查看电脑手机是否相连: 下图表示手机已连上电 ...
 - 跟浩哥学自动化测试Selenium -- 浏览器的基本操作与元素定位(3)
			
浏览器的基本操作与元素定位 通过上一章学习,我们已经学会了如何设置驱动路径,如何创建浏览器对象,如何打开一个网站,接下来我们要进行一些复杂的操作比如先打开百度首页,在打开博客园,网页后退,前进等等,甚 ...
 - Resharp使用简记
			
一图流: 拾贝: .字符串引号中直接回车键自动添加连接字符串 Ctrl+B:转到定义 Ctr+F11:展示类结构 Ctr+Alt+j:包围代码块 Ctr+\:注释和取消注释 Alt+Ins:重构 Ct ...
 - [JSON].exists( keyPath )
			
语法:[JSON].exists( keyPath ) 返回:[True | False] 说明:检测指定键名路径是否存在 示例: Set jsonObj = toJson("{div:{' ...
 - Vue动画效果
			
1.哪些元素/那些组件适合在那些条件下实现动画效果 条件渲染 (使用 v-if) 条件展示 (使用 v-show) 动态组件 组件根节点 简单经典例子:(文字隐藏到显示效果) <div> ...
 - 【递归入门】组合的输出:dfs
			
题目描述 排列与组合是常用的数学方法,其中组合就是从n个元素中抽出r个元素(不分顺序且r < = n),我们可以简单地将n个元素理解为自然数1,2,…,n,从中任取r个数. 现要求你不用递归的方 ...
 - POJ 2826 An Easy Problem?!(线段交点+简单计算)
			
Description It's raining outside. Farmer Johnson's bull Ben wants some rain to water his flowers. Be ...
 - wpa_supplicant下行接口浅析
			
wpa_supplicant通过socket通信机制实现下行接口,与内核进行通信,获取信息或下发命令. 以下摘自http://blog.csdn.net/fxfzz/article/details/6 ...
 - PAT L2-005 集合相似度
			
https://pintia.cn/problem-sets/994805046380707840/problems/994805070149828608 给定两个整数集合,它们的相似度定义为:/.其 ...