题意:从任意一个任意一个可走的点开始找一个最长的路,这条路如果有转弯的话,
那么必须是 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. ffmpeg mp3 to m3u8

    ffmpeg -i Sunshine.mp3 -c:a libmp3lame -b:a 128k -map 0:0 -f segment -segment_time 10 -segment_list ...

  2. Maven 简单配置gpg

    1. 下载maven到指定目录,指定对应的gpg的执行命令所需要的属性.这里比如下载解压后的maven目录是: C:\maven-apache-3.3.2 ,那么配置文件目录是: C:\maven-a ...

  3. Windows KB2984972安装后堵住了一个windows 7 桌面可以多个用户远程访问桌面的漏洞。

    之前网络上有方法可以实现2个用户同时使用一个windows 7,一个在终端,一个通过远程桌面. 安装了这个kb后,就无法同时登陆了,同一时间只有一个用户可以登陆windows 7

  4. IOC性能对比

  5. 常用的sql脚本 游标遍历操作

    Declare @id int DECLARE cursor_data CURSOR FOR --这里是取得数据源 OPEN cursor_data FETCH FROM cursor_data IN ...

  6. 39. Volume Rendering Techniques

    Milan Ikits University of Utah Joe Kniss University of Utah Aaron Lefohn University of California, D ...

  7. 【转】ASP.NET WEB API系列教程

    from: 西瓜小强 http://www.cnblogs.com/risk/category/406988.html ASP.NET Web API教程(六) 安全与身份认证 摘要: 在实际的项目应 ...

  8. asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”

    asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler” http:// ...

  9. Nginx upstream 长连接

    原文: http://bollaxu.iteye.com/blog/900424 Nginx upstream目前只有短连接,通过HTTP/1.0向后端发起连接,并把请求的"Connecti ...

  10. html5开发之viewport使用

    随着高端手机(Andriod,Iphone,Ipod,WinPhone等)的盛行,移动互联应用开发也越来越受到人们的重视,用html5开发移动应用是最好的选择.然而,每一款手机有不同的分辨率,不同屏幕 ...