题意:从任意一个任意一个可走的点开始找一个最长的路,这条路如果有转弯的话,
那么必须是 90度,或者没有转弯!

思路: 首先用dfs将所有可走点开始的 8 个方向上的线段的最长长度求出来 !
step[i][j][k] 表示的是(i,j)沿着k方向一直走到头或者转弯时的最长步数!
最后枚举每一个可走点转弯为90度的路径,找到最长的长度!
step[i][j][k1] + step[i][j][k2] 就是 (i, j)这个点 k1 和 k2方向构成90度!

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 105
using namespace std; int step[N][N][];
int dir[][] = { {, }, {, }, {-, }, {, -}, {-, -}, {, }, {-, }, {, -} };
int index[][] = { {, }, {, }, {, }, {, }, {, }, {, }, {, }, {, }};//每一个节点所对应的转弯的枚举
char mp[N][N], vis[N][N];
int n; bool judge(int x, int y){
if(x < || y < || x > n || y > n)
return false;
if( mp[x][y] == '#') return false; return true;
} void dfs(int x, int y){
for(int i = ; i < ; ++i){
int xx = x + dir[i][];
int yy = y + dir[i][];
if(!judge(xx, yy))
step[x][y][i] = ;
else{
if( !step[xx][yy][i] )//记忆话的赶脚
dfs(xx, yy);
step[x][y][i] = + step[xx][yy][i];
}
}
} int main(){
while(scanf("%d", &n) && n){
memset(step, , sizeof(step));
memset(vis, , sizeof(vis));
for(int i = ; i <= n; ++i)
scanf("%s", mp[i]+); for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j)
if(mp[i][j] == '.')
dfs(i, j); int maxN = -;
for(int i=; i <= n; ++i)
for(int j = ; j <= n; ++j){
if(mp[i][j] == '.')
for(int k = ; k < ; ++k)
maxN = max(maxN, step[i][j][index[k][]] + step[i][j][index[k][]] );
}
printf("%d\n", maxN - );//因为多加了一次拐点!
}
return ;
}

2014 网选 5024 Wang Xifeng's Little Plot的更多相关文章

  1. HDU 5024 Wang Xifeng's Little Plot (DP)

    题意:给定一个n*m的矩阵,#表示不能走,.表示能走,让你求出最长的一条路,并且最多拐弯一次且为90度. 析:DP,dp[i][j][k][d] 表示当前在(i, j)位置,第 k 个方向,转了 d ...

  2. HDU 5024 Wang Xifeng's Little Plot(枚举)

    题意:求一个图中只有一个90°拐点的路的最大长度. 分析:枚举每一个为'.'的点,求出以该点为拐点的八种路中的最大长度,再比较所有点,得出最大长度即可. 如上样例,这样是个90°的角... 注意:最多 ...

  3. HDU 5024 Wang Xifeng&#39;s Little Plot 搜索

    pid=5024">点击打开链接 Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  4. [ACM] HDU 5024 Wang Xifeng&#39;s Little Plot (构造,枚举)

    Wang Xifeng's Little Plot Problem Description <Dream of the Red Chamber>(also <The Story of ...

  5. hdu5024 Wang Xifeng's Little Plot (水

    http://acm.hdu.edu.cn/showproblem.php?pid=5024 网络赛 Wang Xifeng's Little Plot Time Limit: 2000/1000 M ...

  6. 2014 网选 上海赛区 hdu 5047 Sawtooth

    题意:求n个'M'型的折线将一个平面分成的最多的面数! 思路:我们都知道n条直线将一个平面分成的最多平面数是 An = An-1 + n+1 也就是f(n) = (n*n + n +2)/2 对于一个 ...

  7. 2014 网选 广州赛区 hdu 5025 Saving Tang Monk(bfs+四维数组记录状态)

    /* 这是我做过的一道新类型的搜索题!从来没想过用四维数组记录状态! 以前做过的都是用二维的!自己的四维还是太狭隘了..... 题意:悟空救师傅 ! 在救师父之前要先把所有的钥匙找到! 每种钥匙有 k ...

  8. 2014 网选 广州赛区 hdu 5023 A Corrupt Mayor's Performance Art

    #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #d ...

  9. 2014 网选 5011 Game(Nim游戏,数学题)

    /* 题意:Nim游戏! 思路:通过异或,判断将n个数表示成二进制的形式之后,是否对应位的数字1 的个数是偶数! */ #include<iostream> using namespace ...

随机推荐

  1. Android Application 对象介绍

    What is Application Application和Actovotu,Service一样是android框架的一个系统组件,当android程序启动时系统会创建一个 application ...

  2. linux开发神器--Tmux

    在Linux上工作的朋友,可能会常常遇到这种情况: 痛点1: 在公司用putty连着Linux开发机,程序正跑着,不知不觉到了下班的时候,要和老婆/女朋友约会了,但是程序还没跑完,并且进度有点紧,还得 ...

  3. 详解eNSP下的PPP之MP、PAP/CHAP认证实验配置

    一.PPP MP实验(用虚拟模板配置) 1.拓扑图

  4. 报错:LINQ to Entities 不识别方法

    大致是: var products = db.Products.Select(new ProductVm{Name=SomeMethod() }); 针对IQueryable集合的查询操作会被LINQ ...

  5. WIN7只能上QQ打不开网页,使用CMD输入netsh winsock reset

    此类问题可以用腾讯电脑管家电脑诊所一键修复,请点击上方的[立即修复]即可. 附:手动修复步骤(来源:腾讯电脑管家电脑诊所,自动修复请点击上方的[立即修复])方案一:手动设置DNS(说明:如果您使用DN ...

  6. Codeforces Round #384 (Div. 2) E. Vladik and cards 状压dp

    E. Vladik and cards 题目链接 http://codeforces.com/contest/743/problem/E 题面 Vladik was bored on his way ...

  7. ecshop 加广告出现广告位的宽度值必须在1到1024之间

    打开 admin/ad_position.php这个文件,搜索1024,这里你会搜到两个地方 在236行左右 if ($ad_width > 1024 || $ad_width < 1) ...

  8. 2. MongoDB基本操作 —— 用Mongo.exe操作数据库增删改查

    一.开篇 传统的关系数据库一般由数据库(database).表(table).记录(record)三个层次概念组成,MongoDB是由数据库(database).集合(collection).文档对象 ...

  9. drupal7 Views Slideshow 简单教程

    一.下载安装(略) 二.内容类型建立(过程略,首页幻灯),字段建立(过程略)主要有2个字段,图片字段 和 指向链接字段 三.view 1.建立一个新的view,名称为frontbanner 显示为内容 ...

  10. sql:pivot unpivot

    pivot  行转列 unpivot  列转行 源码跑步起来 这是能跑起来的 源码转自 http://www.cnblogs.com/zhangzt/archive/2010/07/29/178782 ...