hdu5024 Wang Xifeng's Little Plot (水
http://acm.hdu.edu.cn/showproblem.php?pid=5024
网络赛
Wang Xifeng's Little PlotTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 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 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
Recommend
hujie
|
题意:
给出矩阵地图,.能走#不能走,八个方向都可以走,求某个点开始走一波直线然后转个90度的弯再走一波直线的最长的路能走多长。
题解:
预处理出每个点向各个方向能走多长,然后枚举拐弯处。
代码:
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usll unsigned ll
#define mz(array) memset(array, 0, sizeof(array))
#define mf1(array) memset(array, -1, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("1biao.out","w",stdout)
#define mp make_pair
#define pb push_back
const double eps=1e-;
const double pi=acos(-1.0); const int gx[]= {,,-,};
const int gy[]= {,,,}; const int maxn=;
int n;
char a[maxn][maxn];
int b[maxn][maxn][];///0- 1| 2/ 3"\" b[x][y][dr],在dr方向,以x,y为端点的最长线段的长度,包括x,y inline bool in(const int &x,const int &y) {
return(x>= && x<=n && y>= && y<=n);
} void gank(int X,int Y,int dr) {
int x=X,y=Y;
bool flag=;
int fx,fy;
int step=;
while(in(x,y)) {
//printf("a[%d][%d]=%c\n",x,y,a[x][y]);
if(!flag && a[x][y]=='.') {
flag=;
fx=x;
fy=y;
step=;
}
if(flag && a[x][y]=='#') {
flag=;
int nStep=;
//printf("%d,%d,%d,%d,%d\n",x,y,fx,fy,step);
while(in(fx,fy) && !(fx==x && fy==y)) {
b[fx][fy][dr]=max(nStep,step-nStep+);
fx+=gx[dr];
fy+=gy[dr];
nStep++;
}
}
x+=gx[dr];
y+=gy[dr];
step++;
} if(flag) {
flag=;
int nStep=;
//printf("%d,%d,%d,%d,%d\n",x,y,fx,fy,step);
while(in(fx,fy) && !(fx==x && fy==y)) {
b[fx][fy][dr]=max(nStep,step-nStep+);
fx+=gx[dr];
fy+=gy[dr];
nStep++;
}
} } int farm() {
int i,j;
mz(b); ///-
FOR(i,,n) {
gank(i,,);
} ///|
FOR(i,,n) {
gank(,i,);
} ///"/"
FOR(i,,n) {
gank(i,,);
//printf("start at %d,%d:\n",n,i);
gank(n,i,);
} ///"\"
FOR(i,,n) {
gank(i,,);
gank(,i,);
} int ans=;
FOR(i,,n) {
FOR(j,,n) {
//printf("%d,%d %d %d %d %d\n",i,j,b[i][j][0],b[i][j][1],b[i][j][2],b[i][j][3]);
ans=max(ans,b[i][j][]+b[i][j][]-);
ans=max(ans,b[i][j][]+b[i][j][]-);
}
}
return ans;
} int main() {
int i,j;
while(scanf("%d",&n)!=EOF) {
if(n==)break;
FOR(i,,n) {
FOR(j,,n)scanf(" %c",&a[i][j]);
} // printf("\n%d\n",n);
// FOR(i,1,n){
// FOR(j,1,n)printf("%c",a[i][j]);
// puts("");
// }
printf("%d\n",farm());
}
return ;
}
hdu5024 Wang Xifeng's Little Plot (水的更多相关文章
- HDU 5024 Wang Xifeng's Little Plot (DP)
题意:给定一个n*m的矩阵,#表示不能走,.表示能走,让你求出最长的一条路,并且最多拐弯一次且为90度. 析:DP,dp[i][j][k][d] 表示当前在(i, j)位置,第 k 个方向,转了 d ...
- 2014 网选 5024 Wang Xifeng's Little Plot
题意:从任意一个任意一个可走的点开始找一个最长的路,这条路如果有转弯的话, 那么必须是 90度,或者没有转弯! 思路: 首先用dfs将所有可走点开始的 8 个方向上的线段的最长长度求出来 ! step ...
- HDU 5024 Wang Xifeng's Little Plot(枚举)
题意:求一个图中只有一个90°拐点的路的最大长度. 分析:枚举每一个为'.'的点,求出以该点为拐点的八种路中的最大长度,再比较所有点,得出最大长度即可. 如上样例,这样是个90°的角... 注意:最多 ...
- HDU 5024 Wang Xifeng's Little Plot 搜索
pid=5024">点击打开链接 Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others) Memory ...
- [ACM] HDU 5024 Wang Xifeng's Little Plot (构造,枚举)
Wang Xifeng's Little Plot Problem Description <Dream of the Red Chamber>(also <The Story of ...
- hdu5024-Wang Xifeng's Little Plot
此题一开始用暴力做,后来发现斜着走的时候其实暴力不太好写,于是改用搜索写了 #include <iostream> #include <stdio.h> #include &l ...
- 2014 ACM/ICPC Asia Regional Guangzhou Online
Wang Xifeng's Little Plot http://acm.hdu.edu.cn/showproblem.php?pid=5024 预处理出每个点八个方向能走的最远距离,然后枚举起点,枚 ...
- The 2014 ACMICPC Asia Regional Guangzhou Online
[A]-_-/// [B]线段树+位运算(感觉可出) [C]地图BFS,找最长线 [D]地图BFS,加上各种复杂情况的最短路-_- [E]-_-/// [F]三分+圆与线段的交点,计算几何 [G]-_ ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
随机推荐
- Bzoj4066 简单题
Time Limit: 50 Sec Memory Limit: 20 MBSubmit: 2185 Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...
- [NOIP2015] 提高组 洛谷P2615 神奇的幻方
题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...
- 数据结构1 线段树查询一个区间的O(log N) 复杂度的证明
线段树属于二叉树, 其核心特征就是支持区间加法,这样就可以把任意待查询的区间$[L, R]$分解到线段树的节点上去,再把这些节点的信息合并起来从而得到区间$[L,R]$的信息. 下面证明在线段树上查询 ...
- Java 开发技巧
一 读取配置文件 1 Properties读取配置文件 编写配置文件config.properties放在普通java工程的src目录(如果是maven工程就放在工程的src/main/resourc ...
- 深入JVM-常用Java虚拟机参数
一.跟踪调试参数 1.1 跟踪垃圾回收-读懂虚拟机日志 Java的一大特色就是支持自动的垃圾回收(GC),但是有时候,如果垃圾回收频繁出现,或者占用了太长的CPU时间,就不得不引起重视.此时,就需要一 ...
- IOS VFL屏幕自适应
-(void)fun1{ //注意使用VFL,不用设置视图的frame UIView *view = [[UIView alloc] init]; view.backgroundColor = [UI ...
- linux程序处理po多语言的两种脚本配置方式
1.在configure.ac里面配置ALL_LINGUAS,然后调用AM_GLIB_GNU_GETTEXT 2.在po目录下面放置LINGUAS文件,由gettextize来生成并处理
- sphinx安装记录 转
[转]sphinx服务器安装及配置详解 安装PHP sphinx扩展 1.架构:ip192.168.0.200 redhat5.4(64位)2.安装 #cd /usr/local/src #y ...
- Ubuntu下apt-get命令详解
在Ubuntu下,apt-get近乎是最常用的shell命令之一了,因为他是Ubuntu通过新立得安装软件的常用工具命令. 本文列举了常用的APT命令参数: apt-cache search pack ...
- 9月5日网页基础知识 通用标签、属性(body属性、路径、格式控制) 通用标签(有序列表、无序列表、常用标签)(补)
网页基础知识 一.HTML语言 HTML语言翻译汉语为超文本标记语言. 二.网页的分类 1.静态页面:在静态页面中修改网页内容实际上就是修改网页原代码,不能从后台操作,数据来只能来源于原于代码.静态网 ...