http://acm.hdu.edu.cn/showproblem.php?pid=5024

网络赛

Wang Xifeng's Little Plot

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 239    Accepted Submission(s): 156

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
 
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 (水的更多相关文章

  1. HDU 5024 Wang Xifeng's Little Plot (DP)

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

  2. 2014 网选 5024 Wang Xifeng's Little Plot

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

  3. HDU 5024 Wang Xifeng's Little Plot(枚举)

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

  4. HDU 5024 Wang Xifeng&#39;s Little Plot 搜索

    pid=5024">点击打开链接 Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  5. [ACM] HDU 5024 Wang Xifeng&#39;s Little Plot (构造,枚举)

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

  6. hdu5024-Wang Xifeng's Little Plot

    此题一开始用暴力做,后来发现斜着走的时候其实暴力不太好写,于是改用搜索写了 #include <iostream> #include <stdio.h> #include &l ...

  7. 2014 ACM/ICPC Asia Regional Guangzhou Online

    Wang Xifeng's Little Plot http://acm.hdu.edu.cn/showproblem.php?pid=5024 预处理出每个点八个方向能走的最远距离,然后枚举起点,枚 ...

  8. The 2014 ACMICPC Asia Regional Guangzhou Online

    [A]-_-/// [B]线段树+位运算(感觉可出) [C]地图BFS,找最长线 [D]地图BFS,加上各种复杂情况的最短路-_- [E]-_-/// [F]三分+圆与线段的交点,计算几何 [G]-_ ...

  9. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

随机推荐

  1. 一次性下载CVPR2016的所有文章

    wget --no-clobber --convert-links --random-wait -r -p -E -e robots=off -U mozilla http://www.cv-foun ...

  2. Matlab的实时编辑器(Live Script)

    Matlab的实时编辑器(Live Script) 看到伟哥换用了matlab2016a,里面集成了acf行人检测算法,感觉挺好的,索性也从matlab2014a跨越到matlab2016a. 安装后 ...

  3. 【BZOJ-1260】涂色paint 区间DP

    1260: [CQOI2007]涂色paint Time Limit: 30 Sec  Memory Limit: 64 MBSubmit: 1147  Solved: 698[Submit][Sta ...

  4. Search and Replace的正则表达式

    以下例子均在Search and Replace中适用,EditPlus也有正则表达式,但有点不一样. 1.1 基本操作符 * 重复0次或更多次 + 重复一次或更多次 ? 重复一次 | 或 操作符 ! ...

  5. 快递查询SDK

    简介: 快递查询的SDK,使用的是快递100的智能查询,此SDK只是中间包装了一层而已,单对于普通的快递业务查询已经足够,也省去开发者研究的时间,拿来即用. 用途: 1.对接微信公众平台 2.对接需要 ...

  6. CameraFlash手电筒

    有时候晚上找不到电棒,电灯,咱们可以写个小程序,利用照相机的闪光灯临时顶替上代码: 1 package com.linux.cameraflash; import android.hardware.C ...

  7. CF 435B Pasha Maximizes(贪心)

    题目链接: [传送门][1] Pasha Maximizes time limit per test:1 second     memory limit per test:256 megabytes ...

  8. pythong中字符串strip的用法

    strip的用法是去除字符串中前后两端的xx字符,xx是一个字符数组,并不是去掉“”中的字符串, 数组中包含的字符都要在字符串中去除.默认去掉空格,lstrip则是去掉左边的,rstrip是右边的 见 ...

  9. JSP+JavaBean+Servlet+Oracle新增功能中对Date类型的字段的处理

    Oracle库中userinfo表borth字段是Date类型,age年纪字段是int类型.age字段要根据borth来自动计算 先说一下我遇到的问题: insert into的时候遇到日期转换类型错 ...

  10. mysql 某周的起始和结束日期

    转自:http://bbs.csdn.net/topics/370096126 t_table有数据如下:year    Week2011    22011    32011    42011     ...