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 ;
}

最新文章

  1. SharedPreferences.Editor 的apply()与commit()方法的区别
  2. 【特别推荐】10款唯美浪漫的婚礼 &amp; 结婚纪念网站模板
  3. [转][Android]FragmentPagerAdapter与FragmentStatePagerAdapter使用详解与区别
  4. 网络流最经典的入门题 各种网络流算法都能AC。 poj 1273 Drainage Ditches
  5. cpoint
  6. 信息传递--NOIP2015 day1 T2--暴力
  7. LoadRunner显示中文乱码的问题
  8. rdesktop命令连接Win7远程桌面
  9. 【C语言】写一个函数,实现字符串内单词逆序
  10. CDOJ 1270 Playfair
  11. 用jenkins创建节点
  12. 今天我给你们推荐一本书《Linux就该这么学》!!!
  13. 并行开发-Task
  14. 用juniversalchardet解决爬虫乱码问题
  15. Linux 修改默认的 yum 源
  16. Spring框架学习——Spring的体系结构详解
  17. 怎么在eclipse中访问webservice
  18. Fiddler Web Debugger的代理功能(图文详解)
  19. VC++ 6.0 C8051F340 MFC programming note
  20. Hibernate与数据库的触发器协同工作

热门文章

  1. Hadoop jobhistory历史服务器
  2. java integer对象判断两个数字是否相等
  3. NuGet在创建pack时提示”The replacement token &#39;author&#39; has no value“问题解决
  4. 向列布局动态添加F7
  5. django 快速搭建blog
  6. Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort(暴力)
  7. CF 84D Doctor(二分)
  8. CentOs安装Scrapy出现error: Setup script exited with error: command ‘gcc’ failed with exit status 1错误解决方案
  9. 一文彻底了解join的各种用法
  10. Base64复习