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. 有关于/home出现100%被占用 与 vnc的关系

    我在远程服务器时,通常使用的程序是vnc.因为vnc可以图形化界面,操作效果比用putty好很多. 但是,我发现使用vnc有一个问题,就是/home占用空间会达到100%. [zy@islab62 ~ ...

  2. [方法]本来好的中文在winEdt中打开变成乱码

    场景:本来在winEdt中使用中文的tex文件,使用xelatex可以编译成pdf,今天打开该tex文件,所有中文变得不可读,统统乱码. 解决方法:在保存tex文件时使用的是utf-8保存的,所以在打 ...

  3. POJ1007

    2014-08-22   题目意思: 按照各个字符串的逆序数排序(稳定排序,即若A=B,则AB的顺序还是原来的样子) 思路: 求出每个字符串的逆序数后,排序输出即可 代码: //Memory Time ...

  4. 常见 wifi热点的linux 驱动

    小度Wifi.360Wifi Windows.linux驱动 小度wifi什么的就是一个无线网卡,当然可以自由使用,然官方却说不支持无限网卡功能… 现提供Windows平台和linux平台的驱动安装方 ...

  5. 关于优化性能<主要是速度方面>的个人心得 【转】

    一个web项目后期的维护主要在于性能方面.数据吞吐量一旦增大各种bug都出来了.那些通过硬件<数据库分表,数据库主从分离,读写分离>等的一些手段此处就不多说了.本文主要在编码方面做一个性能 ...

  6. POJ2063 Investment 【全然背包】

    Investment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8019   Accepted: 2747 Descri ...

  7. easyui的验证

    加一个JS来重写验证,文件名为:validator.js 内容为: //扩展easyui表单的验证 $.extend($.fn.validatebox.defaults.rules, { //验证汉子 ...

  8. NavigationBar--修改返回按钮的标题

    UIBarButtonItem *backItem = [[[UIBarButtonItem alloc] init] autorelease]; backItem.title = @"返回 ...

  9. git本地仓库与github远程仓库链接协议问题

    前提条件:有github账号,本地安装了git,能上网. 环境:ubuntu14.0.4LTS 首先在你得在github上创建一个仓库new repository,然后再本地创建一个文件夹mkdir ...

  10. VS中C++对象的内存布局

    本文主要简述一下在Visual Studio中C++对象的内存布局,这里没有什么测试代码,只是以图文的形式来描述一下内存分布,关于测试的代码以及C++对象模型的其他内容大家可以参考一下陈皓先生的几篇博 ...