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. shell脚本积累

    统计当前目录下文件夹的大小 for d in $(ls) do du -sh ./$d done 获取之前日期date  +"%Y%m%d" -d  "-n days&q ...

  2. 给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,...,n-1],其中B中的元素B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1]。不能使用除法。

    // test14.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  3. 中国餐馆过程(CRP)

    查如何事先确定聚类簇数目发现的,是对狄利克雷过程的(DP)的一种解释. 假设一个中国餐馆有无限的桌子,第一个顾客到来之后坐在第一张桌子上.第二个顾客来到可以选择坐在第一张桌子上,也可以选择坐在一张新的 ...

  4. Matlab实现求a到b被c整除的个数

    我先想到的是for循环........ 然后sum(find(mod(a:b,c)==0)),从10到100得到874,为什么不对呢? 比如a = [1 2 3 4  2 3 4 2],find(a= ...

  5. Checkbox框全选操作,form表单提交与jquery ajax提交两种处理方式

    //1.jquery ajax<script type="text/javascript"> $(function(){ var basePath = $(" ...

  6. Javascript的9张思维导图学习

    思维导图小tips:思维导图又叫心智图,是表达发射性思维的有效的图形思维工具 ,它简单却又极其有效,是一种革命性的思维工具.思维导图运用图文并重的技巧,把各级主题的关系用相互隶属与相关的层级图表现出来 ...

  7. hdu 4676 Sum Of Gcd

    离线+分块!! 思路:序列a[1],a[2],a[3]……a[n] num[i]表示区间[L,R]中是i的倍数的个数:euler[i]表示i的欧拉函数值. 则区间的GCD之和sum=∑(C(num[i ...

  8. http://www.oschina.net/translate/elasticsearch-getting-started?cmp

    http://www.oschina.net/translate/elasticsearch-getting-started?cmp

  9. hdu 1426 Sudoku Killer

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1426 #include<stdio.h> #include<math.h> #in ...

  10. yum工具介绍

    当你的linux处于联网状态时,yum工具能够非常方便的在Linux上安装各种软件.补丁等等,而且最重要的一点是完全不用管包的依赖关系.只需要简单的指定你要安装的软件名称,其他工作几乎都交给yum了, ...