HDU 5024 Wang Xifeng's Little Plot 搜索

时间:2022-04-14 22:10:11

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. &lbrack;ACM&rsqb; HDU 5024 Wang Xifeng&amp&semi;&num;39&semi;s Little Plot (构造,枚举)

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

  2. HDU 5024 Wang Xifeng&&num;39&semi;s Little Plot &lpar;DP&rpar;

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

  3. HDU 5024 Wang Xifeng&&num;39&semi;s Little Plot(枚举)

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

  4. 2014 网选 5024 Wang Xifeng&&num;39&semi;s Little Plot

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

  5. hdu5024 Wang Xifeng&&num;39&semi;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&semi;amp&semi; HDU 2410 Barbara Bennett&amp&semi;&num;39&semi;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&amp&semi;&num;39&semi;s Password (简单模拟题)

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

  9. HDU ACM 1098 Ignatius&amp&semi;&num;39&semi;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. 每天一个linux命令:route命令

    Linux系统的route命令用于显示和操作IP路由表(show / manipulate the IP routing table).要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或 ...

  2. iOS学习13之OC NSString类

    C语言中,字符串是有char(ASC||码)字符组成. OC中,字符串是由unichar(Unicode)字符组成. 1.字符串(NSString) NSString:不可变字符串,即:创建以后,内容 ...

  3. freemarker编辑器eclipse插件

    freemarker编辑器eclipse插件 支持语法高亮,语法校验,代码提示的工具 freemarker  IDE(JBoss): http://download.jboss.org/jbossto ...

  4. 如何在cocos2d项目中enable ARC

    如何在cocos2d项目中enable ARC 基本思想就是不支持ARC的代码用和支持ARC的分开,通过xcode中设置编译选项,让支持和不支持ARC的代码共存. cocos2d是ios app开发中 ...

  5. 关于&OpenCurlyDoubleQuote;&period;bash&lowbar;profile”和&OpenCurlyDoubleQuote;&period;bashrc”区别的总结

    bash的startup文件 Linux shell是用户与Linux系统进行交互的媒介,而bash作为目前Linux系统中最常用的shell,它支持的startup文件也并不单一,甚至容易让人感到费 ...

  6. 【JEECG技术文档】JEECG 组织机构导入V3&period;7

    1.功能介绍 组织机构导入 提供组织机构模版导入功能,使用户更快速的创建组织机构 要使用组织机构导入功能需要完成以下步骤: 1. 下载模版excel 2. 填写组织机构信息 3. 点击导入-选择文件- ...

  7. 百度钱包、百付宝、baifubao接入支付的常见问题

    [5004:参数非法,请检查输入参数后重试.]:检查是否缺少了其它必要的参数,我当时是缺少了order_no [5804,抱歉,订单创建失败,请联系客服处理]:即验证签名失败,这个只能参考文档进行处理 ...

  8. OpenCV 学习笔记03 凸包convexHull、道格拉斯-普克算法Douglas-Peucker algorithm、approxPloyDP 函数

    凸形状内部的任意两点的连线都应该在形状里面. 1 道格拉斯-普克算法 Douglas-Peucker algorithm 这个算法在其他文章中讲述的非常详细,此处就详细撰述. 下图是引用*的.ε ...

  9. HTTP Header之Content-Type

    HTTP Header之Content-Type   目录 1. HTTP Header 2. 文件请求和接口请求 3. 几种 Content-Type 3.1 application/x-www-f ...

  10. 在mfc中picture控件中显示Mat图片&lt&semi;转&gt&semi;

    void ShowMatImgToWnd(CWnd* pWnd, cv::Mat img) { if(img.empty()) return; CRect drect; pWnd->GetCli ...