题意:从任意一个任意一个可走的点开始找一个最长的路,这条路如果有转弯的话,
那么必须是 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. Leetcode 20 Valid Parentheses stack的应用

    判断括号是否合法 1.用stack存入左括号“([{”,遇到相应的右括号“)]}”就退栈 2.判断stack是否为空,可以判断是否合法 class Solution { public: bool is ...

  2. PHP读取流文件

    $filepath = 'http://www.vip.com/down'; $fp = fopen($filepath,"r"); Header("Content-ty ...

  3. JS变量的作用域

    深入理解JavaScript变量的作用域   1.JavaScript的作用域链 2.函数体内部,局部变量的优先级比同名的全局变量高. 3.JavaScript没有块级作用域. 4.函数中声明的变量在 ...

  4. 17数据表&E-R模型&概念数据模型上-选学天轰穿大话数据库视频教程

    大纲:解剖“数据表”,戏说E-R模型,概念数据模型(E-R 到 CDM),使用PowerDesigner创建概念模型,生成逻辑数据模型 土豆超清地址: 腾讯超清地址: 百度云盘下载地址:上传ing,稍 ...

  5. 只写104行代码!在nopCommerce中如何实现自动生成网站地图

    表告诉我说你不知道nopCommerce是什么.它是目前.NET中最流行的完全开源网上商城,由俄罗斯的团队在2008年开始立项一直开发到现在已经是3.3版本了.代码目前托管在codeplex上,有兴趣 ...

  6. How to programmatically new a java class which implements sepecified interface in eclipse plugin development

    http://w3facility.org/question/how-to-programmatically-new-a-java-class-which-implements-sepecified- ...

  7. redis一句话

  8. Linux驱动开发学习笔记(1):LINUX驱动版本的hello world

    1.关于目录    /lib/modules/2.6.9-42.ELsmp/build/   这个是内核源码所在的目录    一般使用这样的命令进入这个目录:cd /lib/modules/$(una ...

  9. PreparedStatement ResultSet

    public int searchProblemDistinctCount() throws Exception { DBOperator dbo = getDBOperator(); try { P ...

  10. Linux2.6 内核的 Initrd 机制解析(转)

    from: https://www.ibm.com/developerworks/cn/linux/l-k26initrd/ 简介: Linux 的 initrd 技术是一个非常普遍使用的机制,lin ...