1033. Labyrinth(dfs)
简单dfs 有一点小小的坑 就是图可能不连通 所以要从左上和右下都搜一下 加起来 从讨论里看到的
讨论里看到一句好无奈的回复 “可不可以用中文呀。。。”
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
using namespace std;
char s[][];
int dis[][] = {,,,,-,,,-};
int vis[][],n,num;
int judge(int x,int y)
{
if(x<||y<||x>n||y>n)
return ;
return ;
}
void dfs(int x,int y)
{
int i;
for(i = ; i < ; i++)
{
int tx = dis[i][]+x;
int ty = dis[i][]+y;
if(judge(tx,ty)&&!vis[tx][ty])
{
if(s[tx][ty]=='#')
{
num++;
continue;
}
vis[tx][ty] = ;
if(tx==n&&ty==n)
{
dfs(tx,ty);
continue;
}
if(tx==||ty==||tx==n||ty==n)
num++;
if((tx==&&ty==n)||(ty==&&tx==n))
num++;
dfs(tx,ty);
}
}
}
int main()
{
int i,j;
scanf("%d",&n);
for(i = ; i <= n ; i++)
for(j = ; j <= n ; j++)
cin>>s[i][j];
vis[][] = ;
dfs(,);
if(!vis[n][n])
{
vis[n][n] = ;
dfs(n,n);
}
printf("%d\n",num*);
return ;
}
1033. Labyrinth(dfs)的更多相关文章
- URAL.1033 Labyrinth (DFS)
URAL.1033 Labyrinth (DFS) 题意分析 WA了好几发,其实是个简单地DFS.意外发现这个俄国OJ,然后发现ACRUSH把这个OJ刷穿了. 代码总览 #include <io ...
- URAL 1033 Labyrinth
E - Labyrinth Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submi ...
- 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列的图,让你求’*‘这个元素上下左右相连的连续的’.‘有多少(本身也算一个), ...
- Labyrinth 树的直径加DFS
The northern part of the Pyramid contains a very large and complicated labyrinth. The labyrinth is d ...
- 【hihoCoder】1033: 交错和
初探数位dp 介绍了数位类统计的基础知识.以下列出其中的基础点: 基本问题 统计在区间[l, r]中满足条件的数的个数 思路 1. [l, r] 将问题转换为 在[0, r]中满足条件的个数 - 在[ ...
- 2014百度之星资格赛 1004:Labyrinth(DP)
Labyrinth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu---------(1026)Ignatius and the Princess I(bfs+dfs)
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- Codeforces Educational Codeforces Round 5 C. The Labyrinth 带权并查集
C. The Labyrinth 题目连接: http://www.codeforces.com/contest/616/problem/C Description You are given a r ...
随机推荐
- 微信消息处理JAXP-dom解析
package cn.lihainan.test; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import ...
- Ubuntu下的网络配置(USTC)
1. 配置静态ip ubuntu的网络配置信息放在 /etc/network/interfaces 中 sudo gedit /etc/network/interfacesauto lo 下 ...
- eclipse不能创建java虚拟机-解决方法
找到eclipse目录下的eclipse.ini,可以看到如下内容: -startup plugins/org.eclipse.equinox.launcher_1.1.0.v20100507.jar ...
- 备份apt目录节省下载时间
备份与清理 * 备份快速设置已下载的部分软件包,以便重装系统再次使用,免去重新下载的时间 tar cizvf backup.tar.gz /var/cache/apt/archives ...
- IOS 后台运行
默认情况下,当app被按home键退出后,app仅有最多5秒钟的时候做一些保存或清理资源的工作.但是应用可以调用UIApplication的beginBackgroundTaskWithExpirat ...
- 阿里云CentOS6.3 安装MongoDB教程
安装说明 系统环境:Centos-6.3安装软件:mongodb-linux-x86_64-2.2.2.tgz下载地址:http://www.mongodb.org/downloads安装机器:192 ...
- iOS开发之数据存取3-CoreData自定义数据类型
当系统提供的类型不能达到我们的使用要求时,比如我想在CoreData中存储UIColor,该怎么办呢? 这时候就要用到CoreData中非常强大的一个存储类型了:Transformable 下面将通过 ...
- ByteArrary(优化数据存储和数据流)
原地址:http://www.unity蛮牛.com/blog-1801-799.html 首页 博客 相册 主题 留言板 个人资料 ByteArrary(优化数据存储和数据流) 分类:unity ...
- poj 1562 Oil Deposits (广搜,简单)
题目 简单的题目,只是测试案例的输入后面可能有空格,所以要注意一下输入方式. #define _CRT_SECURE_NO_WARNINGS //题目的案例输入n,m后面有些貌似有空格... #inc ...
- Matlab安装
第一步:下载MATLAB 7.0,下载自己百度下就好. 三个ios文件 第二步:把每个IOS文件直接右键解压就好. 第三步:打开第一个解压文件夹.双击.exe文件 第四步:next之后把序列号黏贴上去 ...