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 ...
随机推荐
- [问题解决] /home目录占用率100%
今天发现一个比较奇怪的现象,linux系统下一个目录挂在存储下,df -Th 显示该目录使用率100%, du 该目录显示只用了2%, 后来发现是由于进程占用了被删掉的文件空间导致.举例如下: [ro ...
- 将Linux下编译的warning警告信息输出到文件中[整理笔记]
Linux中,脚本语言环境中,即你用make xxx即其他一些普通linux命令,比如ls,find等,不同的数字,代表不同的含义: 数字 含义 标准叫法0 标准输入 stdin = standar ...
- Codeforces 325D
#include <cstdio> #include <algorithm> #include <cstring> #include <cstdlib> ...
- SQL Server 获取服务器信息
最近做了一个小工具,里面涉及到一些取SQL Server 服务器信息的一些东西,找了好久,找到一个不错的,贴出来分享. 系统函数 SERVERPROPERTY ( propertyname ) 包含要 ...
- Data Structure(3)——软考阶段学习小结
数据结构计算机等级考试中有,自考中有,软考中同样有,可见其内容的重要程度,今天对软考阶段视频学习内容的总结,同样是对前面学习内容的回顾,同样是对后面学习的铺垫. 中结:原本因为之前有过类似的总结,这次 ...
- Effective C++ 条款18
让接口easy被正确使用,不easy被误用 如题目,我们自己的程序接口是面向用户的,程序的目的不可是解决这个问题,并且要让用户easy使用.所以.必须保证我们的程序接口具有非常强的鲁棒性. 怎么保证接 ...
- oauth2认证
using System; using System.Collections.Generic; using System.Security.Cryptography; using System.Con ...
- POJ2229 Sumsets 【递归】
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 13210 Accepted: 5300 Descrip ...
- 你想不到的压缩方法:将javascript文件压缩成PNG图像存储
这样可以做到很高的压缩比,到底有多高,下面会提到.这种方法用到了 canvas 控件,这也意味着只有支持 canvas 控件的浏览器下才有效. 现在你可以看到,上面的图像类似一个噪声图像,但它实际上是 ...
- asp.net 使用HttpModule记录全局错误
以前使用Global.asax记录全局的错误日志觉得挺好用,但是如果一个解决方案下有N多个项目,每个下边都需要加一个并且代码都还是重复的,终于有一天无法再忍受这种模式,考虑到HttpModule,直接 ...