URAL 1033 Labyrinth
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
input | output |
---|---|
5 |
198 |
dfs稍微注意一下,两个入口不一定想通,所以需要从两个入口分别进行dfs
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
char map[maxn][maxn];
bool vis[maxn][maxn];
int nxt[][]={,,,,,-,-,};
int sum;
int n;
int dfs(int x,int y){
vis[x][y]=true;
for(int i=;i<=;i++){
int xx=x+nxt[i][];
int yy=y+nxt[i][]; if(map[xx][yy]=='#'){
sum++;
// printf("-------->%d\n",sum);
// printf("---->%d %d\n",xx,yy); }
}
for(int i=;i<=;i++){
int tx=x+nxt[i][];
int ty=y+nxt[i][];
if(tx<||tx>n||ty<||ty>n||vis[tx][ty])
continue;
if(map[tx][ty]=='.'){
vis[tx][ty]=true;
dfs(tx,ty);
}
}
return sum;
} int main(){ while(scanf("%d",&n)!=EOF){
memset(map,,sizeof(map));
memset(vis,false,sizeof(vis));
getchar();
for(int i=;i<=n;i++){
scanf("%s",map[i]+);
getchar();
} for(int i=;i<=n+;i++){
map[][i]='#';
map[i][]='#';
}
for(int i=;i<=n-;i++){
map[n+][i]='#';
map[i][n+]='#';
}
map[][]='.';
map[][]='.';
map[][]='.';
map[n+][n+]='.';
map[n+][n]='.';
map[n][n+]='.'; vis[][]=true;
vis[][]=true;
vis[][]=true;
vis[n+][n+]=true;
vis[n+][n]=true;
vis[n][n+]=true;
int ans=;
sum=;
ans+=dfs(,); sum=;
if(!vis[n][n])
ans+=dfs(n,n); printf("%d\n", ans*);
}
return ;
}
URAL 1033 Labyrinth的更多相关文章
- URAL.1033 Labyrinth (DFS)
URAL.1033 Labyrinth (DFS) 题意分析 WA了好几发,其实是个简单地DFS.意外发现这个俄国OJ,然后发现ACRUSH把这个OJ刷穿了. 代码总览 #include <io ...
- timus 1033 Labyrinth(BFS)
Labyrinth Time limit: 1.0 secondMemory limit: 64 MB Administration of the labyrinth has decided to s ...
- 1033. Labyrinth(dfs)
1033 简单dfs 有一点小小的坑 就是图可能不连通 所以要从左上和右下都搜一下 加起来 从讨论里看到的 讨论里看到一句好无奈的回复 “可不可以用中文呀...” #include <iostr ...
- URAL题解一
URAL题解一 URAL 1002 题目描述:一种记住手机号的方法就是将字母与数字对应,如图.这样就可以只记住一些单词,而不用记住数字.给出一个数字串和n个单词,用最少的单词数来代替数字串,输出对应的 ...
- URAL 1145—— Rope in the Labyrinth——————【求树的直径】
Rope in the Labyrinth Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64 ...
- ural 1145. Rope in the Labyrinth
1145. Rope in the Labyrinth Time limit: 0.5 secondMemory limit: 64 MB A labyrinth with rectangular f ...
- ural 1152. False Mirrors
1152. False Mirrors Time limit: 2.0 secondMemory limit: 64 MB Background We wandered in the labyrint ...
- 【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 ...
随机推荐
- LibreOJ #2003. 「SDOI2017」新生舞会
内存限制:256 MiB 时间限制:1500 ms 标准输入输出 题目类型:传统 评测方式:文本比较 上传者: 匿名 01分数规划(并不知道这是啥..) km或费用流(并不会)验证 屠龙宝刀点击就送 ...
- Android(java)学习笔记124:利用Service在后台播放背景音乐
1. 在android应用程序里,有一种没有UI的类(android.app.Service)——Service.简单来说,Service是一个 background process(背景程序),通过 ...
- groupmod - 修 改 群 组
总览 SYNOPSIS groupmod [-g gid [-o]] [-n group_name ] group 描述 DESCRIPTION groupmod 命 令 会 参 照 你 命 令 列 ...
- cityspace
类别的网址:https://blog.csdn.net/u010069760/article/details/77847595 r,g,b: 250 170 160 parking 244 35 ...
- C++调用C语言编译的so文件
参考链接:https://blog.csdn.net/chenjinlong126/article/details/78990350 一.制作so文件:libadd_c.so或libadd_cpp.s ...
- mysql如何让自增id从1开始设置方法
有两种方式 第一种: 如果表中数据没有用.如果直接删除数据,自动增长ID还是不会从1开始的,可以利用“清空数据表”.这样自动增长ID也将会从1开始. 清空表的sql如下 truncate table ...
- laydate时间控件绑定回调事件
onclick="laydate({istime: true, format: 'YYYY-MM-DD',choose:checkDate});" //回调函数内容 functio ...
- java基础—this关键字
一.this关键字
- if...else...这段代码打印结果,并简述其理由
var age = 20; if (age >= 6) { console.log('teenager'); } else if (age >= 18) { console.log('ad ...
- 创建自定义 Estimator
ref 本文档介绍了自定义 Estimator.具体而言,本文档介绍了如何创建自定义 Estimator 来模拟预创建的 Estimator DNNClassifier 在解决鸢尾花问题时的行为.要详 ...