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. 路由器开发板上的TTL线连接方法

    手头有个MTK双频路由器的开发板,做工良好,但让人蛋疼的是,TTL线没有标注TX/RX/GND/VCC,这个小细节的缺失给使用带来了巨大麻烦.   网上搜了半天也没找到相关电路图,只好遍历测试找到正确 ...

  2. javacript中的mvc设计模式

    以下内容为原创翻译,翻译不对的地方还请原谅,凑合着看吧. 原文网址是: 来源:http://www.alexatnet.com/articles/model-view-controller-mvc-j ...

  3. 利用JavaScript获取页面文档内容

    JavaScript的document对象包含了页面的实际内容,所以利用document对象可以获取页面内容,例如页面标题.各个表单值. <!DOCTYPE html> <html ...

  4. OC 加密

    //MD5加密的结果为128位的二进制数. //所以有128 / 8 = 16字节(8位一个字节). //每八位表示两个16进制数. //MD5 有32个16进制数. //语言层次的所有摘要算法步骤类 ...

  5. error: The shader requires a sampler in slot 0 which hasn't been set [XXXsampler]

    About the sampler, you need to assign it to your pixelshader. m_d3dContext.Get()->PSSetSamplers(0 ...

  6. DelayedOperationPurgatory之purgatory的实现

    purgatory的超时检测 当一个DelayedOpeartion超时(timeout)时,它需要被检测出来,然后调用它的回调方法.这个事情看起来很简单,但做好也并不容易. 0.8.x的Kafka的 ...

  7. (一)、http原理

    谣言粉碎机前些日子发布的<用公共WiFi上网会危害银行账户安全吗?>,文中介绍了在使用HTTPS进行网络加密传输的一些情况,从回复来看,争议还是有的.随着网络越来越普及,应用越来越广泛,一 ...

  8. java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@450b2f48 异常处理

    晕死的错误,改了半天也没想到是这样的原因,基础正要呀... 先看一下警告信息: 07-07 08:32:19.540: WARN/WindowManager(74): Failed looking u ...

  9. POJ1144 Network 无向图的割顶

    现在打算重新学习图论的一些基础算法,包括像桥,割顶,双连通分量,强连通分量这些基础算法我都打算重敲一次,因为这些量都是可以用tarjan的算法求得的,这次的割顶算是对tarjan的那一类算法的理解的再 ...

  10. java基础知识回顾之java Thread类学习(七)--java多线程安全问题(死锁)

    死锁:是两个或者两个以上的线程被无限的阻塞,线程之间互相等待所需资源. 线程死锁产生的条件: 当两个线程相互调用Join()方法. 当两个线程使用嵌套的同步代码块的时候,一个线程占用了另一个线程的锁, ...