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 ...
随机推荐
- js cookie读取
/**存放Cookies: 两个参数,一个是cookie的名子,一个是值*/ function SetCookie(name,value){ var Days = 30; //此 cookie 将被保 ...
- PMC
PMC = Production Material Control 生产及物料控制,通常分为两个部分: PC:生产控制或生产管制(台.日资公司俗称手配)主要职能是生产的计划与生产的进度控制 : MC: ...
- JavaScript实现定点圆周运动
目是这样的:假设有一定点(400px,300px),通过JavaScript使一个直径20px的圆点以 r=180px 为半径围绕该点做匀速圆周运动. 这个问题的整体实现思想应该是这样的,看到“半径” ...
- Linux下 fcntl 函数用法说明
功能描述:根据文件描述词来操作文件的特性. 文件控制函数 fcntl -- file control LIBRARY Standard C Library (libc, ...
- android VoiceRecognition 语音识别并打印到列表上
package com.example.wenandroid; import java.util.ArrayList; import java.util.List; import android.ap ...
- 发送通知:Notification
Intent的主要功能是完成一个Activity跳转到其他Activity或者是Service的操作,表示的是一种 操作的意图. PendingIntent表示的是暂时执行的一种意图,是一种在产生某一 ...
- java中文乱码解决之道(四)—–java编码转换过程
原文出处:http://cmsblogs.com/?p=1475 前面三篇博客侧重介绍字符.编码问题,通过这三篇博客各位博友对各种字符编码有了一个初步的了解,要了解java的中文问题这是必须要了解的. ...
- .net的页面在大并发下偶尔出现503错误
我们开发了一个回调页面,由一个工具负责调用,由于压力非常大,回调页面通过6台服务器负载均衡的: 最近业务系统又再次扩容,回调页面压力成倍增加,在高峰时间段偶尔出现了503错误. 拿到这个问题首先对系统 ...
- Struts2 初体验
Sturts是一款优雅的,可扩展性很强的框架.它是由Struts开发团队和WebWord团队合作,共同开发的一个新的产品.新版本的Struts2 更加容易使用,更加接近Struts所追求的理念.从开发 ...
- 20151120 jsp相关
jsp 声明表示.代码片段及引用 <%@ page language="java" contentType="text/html; charset=UTF-8&qu ...