HDU 5024 Wang Xifeng's Little Plot 搜索
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
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.
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.
3
#.#
##.
..#
3
...
##.
..#
3
...
###
..#
3
...
##.
...
0
3
4
3
5
找两个点要求相距最远,并且最多仅仅能有一个转弯。转弯必须为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's Little Plot 搜索的更多相关文章
- [ACM] HDU 5024 Wang Xifeng's Little Plot (构造,枚举)
Wang Xifeng's Little Plot Problem Description <Dream of the Red Chamber>(also <The Story of ...
- HDU 5024 Wang Xifeng's Little Plot (DP)
题意:给定一个n*m的矩阵,#表示不能走,.表示能走,让你求出最长的一条路,并且最多拐弯一次且为90度. 析:DP,dp[i][j][k][d] 表示当前在(i, j)位置,第 k 个方向,转了 d ...
- HDU 5024 Wang Xifeng's Little Plot(枚举)
题意:求一个图中只有一个90°拐点的路的最大长度. 分析:枚举每一个为'.'的点,求出以该点为拐点的八种路中的最大长度,再比较所有点,得出最大长度即可. 如上样例,这样是个90°的角... 注意:最多 ...
- 2014 网选 5024 Wang Xifeng's Little Plot
题意:从任意一个任意一个可走的点开始找一个最长的路,这条路如果有转弯的话, 那么必须是 90度,或者没有转弯! 思路: 首先用dfs将所有可走点开始的 8 个方向上的线段的最长长度求出来 ! step ...
- 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 ...
- hdu 5024 最长的L型
http://acm.hdu.edu.cn/showproblem.php?pid=5024 找到一个最长的L型,L可以是斜着的 简单的模拟 #include <cstdio> #incl ...
- POJ 3340 & HDU 2410 Barbara Bennett's Wild Numbers(数学)
题目链接: PKU:http://poj.org/problem?id=3340 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2410 Descript ...
- HDU 4772 Zhuge Liang's Password (简单模拟题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772 题面: Zhuge Liang's Password Time Limit: 2000/1000 ...
- HDU ACM 1098 Ignatius's puzzle
分析:裴蜀定理,a,b互质的充要条件是存在整数x,y使ax+by=1.存在整数x,y,使得ax+by=c.那么c就是a,b的公约数. 如果存在数a ,由于对随意x方程都成立.则有当x=1时f(x)=1 ...
随机推荐
- Delphi 获取北京时间(通过百度和timedate网站)
方法一: uses ComObj, DateUtils; function GetInternetTime: string; var XmlHttp: OleVariant; datetxt: str ...
- 合理的keyword密度散布与黑帽SEO之躲藏文本
合理的keyword密度散布与黑帽SEO之躲藏文本 咱们都晓得.关于baidu的keyword排行有一个非常重要的条件即是keyword密度.在咱们的了解中keyword的密度在2%-8%这个规模之内 ...
- Android系统原理与源码分析(1):利用Java反射技术阻止通过按钮关闭对话框
原文出处:博主宇宙的极客http://www.cnblogs.com/nokiaguy/archive/2010/07/27/1786482.html 众所周知,AlertDialog类用于显示对话框 ...
- wcf系列学习5天速成——第三天 事务的使用
今天是速成的第三天,再分享一下WCF中比较常用的一种技术,也就是”事务“. 在B2B的项目中,一般用户注册后,就有一个属于自己的店铺,此时,我们就要插入两张表, User和Shop表. 当然,要么插入 ...
- wcf 速成,转的啊 第一天
作为WCF速成系列,只介绍些项目开发中常用到的实战知识. 学习wcf,还是对其中的几个术语要了解一下.wcf中有一个ABC的概念,就是 第一: "A" 是地址,就是告诉别人我wcf ...
- node.js(七) 子进程 child_process模块
众所周知node.js是基于单线程模型架构,这样的设计可以带来高效的CPU利用率,但是无法却利用多个核心的CPU,为了解决这个问题,node.js提供了child_process模块,通过多进程来实现 ...
- 通过url给action传中文参数乱码解决方案
比如: http://localhost:8080/projectName/dutyCondition.action?admitstate=0¤tStep=我的博客 传到后台的时候 ...
- UIlabel添加背景图片
做UI的时候我们可能想给某个Label添加一个背景图片,但查看的时候会发现好像只有设置背景颜色的方法,不过我们也可以通过这种方式来解决: UIColor *color = [UIColor color ...
- C# List<T>中Select List Distinct()去重复
List<ModelJD> data = myDalJD.GetAllDataList(); List<string> list= new List<string> ...
- the jar file rt.jar has no source attachment
解决方法:rt的source在jdk目录的src.zip文件里,找到jdk目录下的src.zip,添加就行了.