Wang Xifeng's Little Plot

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 556    Accepted Submission(s): 362

Problem Description
《Dream of the Red Chamber》(also 《The Story of the Stone》) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. This novel was created in Qing Dynasty, by Cao Xueqin. But the last 40 chapters of the original
version is missing, and that part of current version was written by Gao E. There is a heart breaking story saying that after Cao Xueqin died, Cao's wife burned the last 40 chapter manuscript for heating because she was desperately poor. This story was proved
a rumor a couple of days ago because someone found several pages of the original last 40 chapters written by Cao. 



In the novel, Wang Xifeng was in charge of Da Guan Yuan, where people of Jia family lived. It was mentioned in the newly recovered pages that Wang Xifeng used to arrange rooms for Jia Baoyu, Lin Daiyu, Xue Baochai and other teenagers. Because Jia Baoyu was
the most important inheritor of Jia family, and Xue Baochai was beautiful and very capable , Wang Xifeng didn't want Jia Baoyu to marry Xue Baochai, in case that Xue Baochai might take her place. So, Wang Xifeng wanted Baoyu's room and Baochai's room to be
located at two ends of a road, and this road should be as long as possible. But Baoyu was very bad at directions, and he demanded that there could be at most one turn along the road from his room to Baochai's room, and if there was a turn, that turn must be
ninety degree. There is a map of Da Guan Yuan in the novel, and redists (In China English, one whose job is studying 《Dream of the Red Chamber》is call a "redist") are always arguing about the location of Baoyu's room and Baochai's room. Now you can solve this
big problem and then become a great redist.
 
Input
The map of Da Guan Yuan is represented by a matrix of characters '.' and '#'. A '.' stands for a part of road, and a '#' stands for other things which one cannot step onto. When standing on a '.', one can go to adjacent '.'s through 8 directions: north, north-west,
west, south-west, south, south-east,east and north-east.



There are several test cases.



For each case, the first line is an integer N(0<N<=100) ,meaning the map is a N × N matrix.



Then the N × N matrix follows.



The input ends with N = 0.
 
Output
For each test case, print the maximum length of the road which Wang Xifeng could find to locate Baoyu and Baochai's rooms. A road's length is the number of '.'s it includes. It's guaranteed that for any test case, the maximum length is at least 2.
 
Sample Input
3
#.#
##.
..#
3
...
##.
..#
3
...
###
..#
3
...
##.
...
0
 
Sample Output
3
4
3
5
 
Source
 

找两个点要求相距最远,并且最多仅仅能有一个转弯。转弯必须为90度。

可以枚举每个可行点为拐点,分别求出八个方向最长距离,然后可以构成直角的两条路径相加。求最大值。

//15MS	1416K
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int maxx,n;
int dir[8][2]={{0,-1},{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1}};
char g[107][107],ans[8];
void bfs(int x,int y)
{
memset(ans,0,sizeof(ans));
for(int i=0;i<8;i++)
{
int xx=x+dir[i][0];
int yy=y+dir[i][1];
while(xx<n&&xx>=0&&yy<n&&yy>=0&&g[xx][yy]=='.')
{ans[i]++;xx+=dir[i][0];yy+=dir[i][1];}
}
for(int i=0;i<8;i++)
maxx=max(maxx,ans[i]+ans[(i+2)%8]);
}
int main()
{
while(scanf("%d",&n),n)
{
for(int i=0;i<n;i++)
scanf("%s",g[i]);
maxx=0;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(g[i][j]=='.')
bfs(i,j);
printf("%d\n",maxx+1);
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

HDU 5024 Wang Xifeng&#39;s Little Plot 搜索的更多相关文章

  1. [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 ...

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

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

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

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

  4. 2014 网选 5024 Wang Xifeng's Little Plot

    题意:从任意一个任意一个可走的点开始找一个最长的路,这条路如果有转弯的话, 那么必须是 90度,或者没有转弯! 思路: 首先用dfs将所有可走点开始的 8 个方向上的线段的最长长度求出来 ! step ...

  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. hdu 5024 最长的L型

    http://acm.hdu.edu.cn/showproblem.php?pid=5024 找到一个最长的L型,L可以是斜着的 简单的模拟 #include <cstdio> #incl ...

  7. POJ 3340 &amp; HDU 2410 Barbara Bennett&#39;s Wild Numbers(数学)

    题目链接: PKU:http://poj.org/problem?id=3340 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2410 Descript ...

  8. HDU 4772 Zhuge Liang&#39;s Password (简单模拟题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772 题面: Zhuge Liang's Password Time Limit: 2000/1000 ...

  9. HDU ACM 1098 Ignatius&#39;s puzzle

    分析:裴蜀定理,a,b互质的充要条件是存在整数x,y使ax+by=1.存在整数x,y,使得ax+by=c.那么c就是a,b的公约数. 如果存在数a ,由于对随意x方程都成立.则有当x=1时f(x)=1 ...

随机推荐

  1. 窗体的扩展样式GWL_EXSTYLE用于SetWindowLong

    SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TRANSPARENT or WS_EX_ ...

  2. LDA(latent dirichlet allocation)

    1.LDA介绍 LDA假设生成一份文档的步骤如下: 模型表示: 单词w:词典的长度为v,则单词为长度为v的,只有一个分量是1,其他分量为0的向量         $(0,0,...,0,1,0,... ...

  3. Qt学习--部件深入--烤猪蹄

    1,进程条--向用户显示程序的当前状态,向用户提示该任务需要多长时间才能够完成. Qt-ProgressBar创建进程条,QProgressBar,为了使进程条担当起进程指示功能,需要执行定义进程条的 ...

  4. hdu 4740

    题目链接 老虎左拐,老鼠右拐,碰到不能走的拐一次,如果还不能走就停下,自己走过的不能走,求相遇的坐标或-1 一个停下之后,另一个还可以走 #include <cstdio> #includ ...

  5. 实现在ios文件读写

    文件都是用来读写数据的,可是哪里都会有潜规则,ios里面读写数据的潜规则你知不知道,你知道不知道!!! 你有没有觉得NSUserDefaults和NSBundle,plist这些玩意阴魂不散,有时候搞 ...

  6. c++犯的错误

    (1) 定义的变量一定要初始化:long long llnum;  int nNum = 4; llnum = nNum; (llnum的值不是4,高四位是随机数)    int型变量赋值给longl ...

  7. POJ3322-经典的游戏搜索问题

    临近毕业真是各种琐事多,好不容易写完几万字蛋疼的论文,又接着户口档案挂靠,毕业旅游,20多个离校盖章,签证被check了几个星期还没消息,希望8月初能走啊. 各种事情之下,人就是懒加心散,好久没写代码 ...

  8. Linux 下编译Android-VLC开源播放器详解(附源码下载)

    这两天需要做音视频播放相关的东西,所以重新找了目前android下的解码库.Android自带的解码库支持不全,因此很多第三方播放器都是自带解码器,绝大部分都是使用FFMpeg作为解码库.我11年的时 ...

  9. js 判断字符串中是否有某字符串

    <script> var test=['<div class="cur"></div>','<div class="cur&qu ...

  10. setter设置器 gutter访问器

    set方法书写规范: 1.必须以set开头,set后跟去掉下划线的实例变量并且首字母大写.ps: setAge:2.一定有参数3.不能有返回值4.一定是对象方法(-开头)5.形参一般是去掉下划线的实例 ...