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. 微信诡异的 40029 不合法的oauth_code

    最近几天在做微信公共平台开发,之前一切正常运行着,发布一套程序出去之后,发现时不时的报错! 小总结下问题出现原因:微信oauth2.0 接口说明 第一步:用户同意授权,获取code 在确保微信公众账号 ...

  2. 【转】如何设置Android软键盘的默认不弹出?

    在开发Anroid的时候,当你打开一个界面的时候,屏幕的焦点会自动停留在第一个EditText中,Android的软键盘默认会自动弹出,用户第一眼连界面都没有看清楚,软键盘就弹出来了,这就影响到了用户 ...

  3. 谈谈php中上传文件的处理

    这是一个表单的时代... 我们在浏览器中编辑自己的信息,会遇到上传头像:在文库中,我们会上传文档......到处存在“上传”这个词. php是最好的语言(其他语言的程序猿们不要打我...).php在处 ...

  4. html+css学习笔记 5[表格、表单]

    表格 -- 默认样式重置 表格标签:     table 表格     thead 表格头     tbody 表格主体     tfoot 表格尾     tr 表格行     th 元素定义表头 ...

  5. Codeforces Round #227 (Div. 2) E. George and Cards 线段树+set

    题目链接: 题目 E. George and Cards time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 ...

  6. Spring中HibernateCallback的用法(转)

    Hibernate的复杂用法HibernateCallback HibernateTemplate还提供一种更加灵活的方式来操作数据库,通过这种方式可以完全使用Hibernate的操作方式.Hiber ...

  7. Unix守护进程

    问题描述:         Unix守护进程 问题解决:     Unix守护进程没有控制终端,终端名设置为问号(?),终端前台进程组ID设置(TPGID)为-1 守护进程编写规则:      (1) ...

  8. 基于EBP的栈帧

    程序的OEP,一开始以 push ebp 和mov ebp esp这两句开始.   原因:c程序的开始是以一个主函数main()为开始的,而函数在访问的过程中最重要的事情就是要确保堆栈的平衡,而在wi ...

  9. uva 11076

    计算出每一位上数字i会出现的次数  累加 #include <cstdio> #include <cstdlib> #include <cmath> #includ ...

  10. Choosing Columns and Expressions to Index

    A key is a column or expression on which you can build an index. Follow these guidelines for choosin ...