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. 树莓派实现远程开机局域网电脑(WOL协议+etherwake+华硕主板Z97)秒变花生壳开机棒

    一.花生壳映射树莓派 参考: http://www.cnblogs.com/EasonJim/p/6100181.html http://www.cnblogs.com/EasonJim/p/6100 ...

  2. 一、swoole安装

    说明:swoole扩展需要安装php环境,这里就不说了. 1.有了PHP环境后,即可安装swoole扩展. swoole扩展下载地址:https://github.com/swoole/swoole- ...

  3. iOS GCD中的dispatch_group

    假如有一组任务,A,B,C,D,其中ABC是可以并行的,D是必须在ABC任务完成后再执行的. (举个场景,比如吃饭前必须先做菜.做饭和买饮料,然后才能开吃) 1.关于ABC的并行: 采用多线程的方式就 ...

  4. 关于adb连接手机offline的问题解决

    win7-64位系统.对于windows系统,adb devices 显示offline一般可能有两个原因: 1 )端口被占用. 解决方式是:查找端口号,结束占用进程: adb nodaemon se ...

  5. 启动和关闭ADB服务(adb start-server和adb kill-server)

    1  Android SDK中的常用命令行工具 在<Android SDK安装目录>\tools目录中带了很多命令行工具.虽然一般的开发人员并不需要完全掌握这些工具的使用方法,但了解这些工 ...

  6. TcpClient类与TcpListener类

    TcpClient类 //构造方法1 TcpClient t = new TcpClient(); t.Connect(); //构造方法2 IPEndPoint iep = ); TcpClient ...

  7. Gated Recurrent Unit (GRU)公式简介

    update gate $z_t$: defines how much of the previous memory to keep around. \[z_t = \sigma ( W^z x_t+ ...

  8. 修改MySQL的默认数据存储引擎

    因为MySQL默认的是MyISAM数据引擎,不支持事务也不支持外键,所以需要用到Innodb引擎,于是决定将mysql的默认引擎设置为innodb.1 . 查看MySQL存储引擎是用的哪个?登录MyS ...

  9. ES6之let(理解闭包)和const命令

    ES6之let(理解闭包)和const命令 最近做项目的过程中,使用到了ES6,因为之前很少接触,所以使用起来还不够熟悉.因此购买了阮一峰老师的ES6标准入门,在此感谢阮一峰老师的著作. 我们知道,E ...

  10. redis理解

    1. Redis是什么 redis是nosql的一种. 这个问题的结果影响了我们怎么用Redis.如果你认为Redis是一个key value store, 那可能会用它来代替MySQL:如果认为它是 ...