1033

简单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)的更多相关文章

  1. URAL.1033 Labyrinth (DFS)

    URAL.1033 Labyrinth (DFS) 题意分析 WA了好几发,其实是个简单地DFS.意外发现这个俄国OJ,然后发现ACRUSH把这个OJ刷穿了. 代码总览 #include <io ...

  2. URAL 1033 Labyrinth

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

  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. Labyrinth 树的直径加DFS

    The northern part of the Pyramid contains a very large and complicated labyrinth. The labyrinth is d ...

  6. 【hihoCoder】1033: 交错和

    初探数位dp 介绍了数位类统计的基础知识.以下列出其中的基础点: 基本问题 统计在区间[l, r]中满足条件的数的个数 思路 1. [l, r] 将问题转换为 在[0, r]中满足条件的个数 - 在[ ...

  7. 2014百度之星资格赛 1004:Labyrinth(DP)

    Labyrinth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 我的cnblogs设置代码

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  2. DB天气app冲刺二阶段第八天

    今天突然感觉应该做收尾工作了 因为马上就要考试了,时间一下子就不够用了.. 今天主要修复了一下bug,然后天气基本能够实时准确了,就是多功能按钮还是没有弄好 准备简化一下功能. 明天看看还有什么需要改 ...

  3. [原创] zabbix学习之旅七:如何远程操作被监控机器

    虽然我们已经创建了一个报警系统,但在实际场景中,运维人员从得到报警到实际解决问题有一定的时差,若业务系统没有做高可用,那业务不得不中断,对于某些要求严格的企业级环境,这是不可容忍的,那有没有方法能让z ...

  4. C#中类型分析中的常见问题 Type - 转

    http://www.cnblogs.com/yuanyuan/archive/2012/08/16/2642281.html 写代码的时候经常需要分析已有类型的信息例如:分析现有类型自动生成类, 或 ...

  5. 1654 方程的解 - Wikioi

    题目描述 Description佳佳碰到了一个难题,请你来帮忙解决.对于不定方程a1+a2+… +ak-1 +ak=g(x),其中k≥2且k ∈ N*,x是正整数,g(x) =xx mod 1000( ...

  6. javaZIP压缩文件

    问题描述: java ZIP压缩文件 问题解决:     说明:         防止创建压缩文件中中文乱码,需要导入的包:     (1)创建ZipOutputStream 注:     以上引用o ...

  7. 【Ural】【1057】Amount of degrees

    数位DP 2009年刘聪<浅谈数位类统计问题> 例题一 从组合数 以及 数位DP的角度都可以做…… 首先转化成求1~n内K进制下只有0.1的数的个数: 考虑K进制下第一个为1的位,剩下的数 ...

  8. 正确使用stl vecotr erase函数

    erase函数要么删作指定位置loc的元素,要么删除区间[start, end)的所有元素. 返回值是指向删除的最后一个元素的下一位置的迭代器 Parameters All parameters ar ...

  9. 【WCF--初入江湖】13 实战

    13 实战 在线升级 using System; using System.Collections.Generic; using System.ComponentModel; using System ...

  10. Unity3D脚本中文系列教程(十四)

    http://dong2008hong.blog.163.com/blog/static/469688272014032134394/ WWWFrom 类Unity3D脚本中文系列教程(十三)辅助类. ...