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度的弯再走一波直线的最长的路能走多长。

题解:

预处理出每个点向各个方向能走多长,然后枚举拐弯处。

代码:

  1. //#pragma comment(linker, "/STACK:102400000,102400000")
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<iostream>
  5. #include<cstring>
  6. #include<algorithm>
  7. #include<cmath>
  8. #include<map>
  9. #include<set>
  10. #include<stack>
  11. #include<queue>
  12. using namespace std;
  13. #define ll long long
  14. #define usll unsigned ll
  15. #define mz(array) memset(array, 0, sizeof(array))
  16. #define mf1(array) memset(array, -1, sizeof(array))
  17. #define minf(array) memset(array, 0x3f, sizeof(array))
  18. #define REP(i,n) for(i=0;i<(n);i++)
  19. #define FOR(i,x,n) for(i=(x);i<=(n);i++)
  20. #define RD(x) scanf("%d",&x)
  21. #define RD2(x,y) scanf("%d%d",&x,&y)
  22. #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
  23. #define WN(x) printf("%d\n",x);
  24. #define RE freopen("D.in","r",stdin)
  25. #define WE freopen("1biao.out","w",stdout)
  26. #define mp make_pair
  27. #define pb push_back
  28. const double eps=1e-;
  29. const double pi=acos(-1.0);
  30.  
  31. const int gx[]= {,,-,};
  32. const int gy[]= {,,,};
  33.  
  34. const int maxn=;
  35. int n;
  36. char a[maxn][maxn];
  37. int b[maxn][maxn][];///0- 1| 2/ 3"\" b[x][y][dr],在dr方向,以x,y为端点的最长线段的长度,包括x,y
  38.  
  39. inline bool in(const int &x,const int &y) {
  40. return(x>= && x<=n && y>= && y<=n);
  41. }
  42.  
  43. void gank(int X,int Y,int dr) {
  44. int x=X,y=Y;
  45. bool flag=;
  46. int fx,fy;
  47. int step=;
  48. while(in(x,y)) {
  49. //printf("a[%d][%d]=%c\n",x,y,a[x][y]);
  50. if(!flag && a[x][y]=='.') {
  51. flag=;
  52. fx=x;
  53. fy=y;
  54. step=;
  55. }
  56. if(flag && a[x][y]=='#') {
  57. flag=;
  58. int nStep=;
  59. //printf("%d,%d,%d,%d,%d\n",x,y,fx,fy,step);
  60. while(in(fx,fy) && !(fx==x && fy==y)) {
  61. b[fx][fy][dr]=max(nStep,step-nStep+);
  62. fx+=gx[dr];
  63. fy+=gy[dr];
  64. nStep++;
  65. }
  66. }
  67. x+=gx[dr];
  68. y+=gy[dr];
  69. step++;
  70. }
  71.  
  72. if(flag) {
  73. flag=;
  74. int nStep=;
  75. //printf("%d,%d,%d,%d,%d\n",x,y,fx,fy,step);
  76. while(in(fx,fy) && !(fx==x && fy==y)) {
  77. b[fx][fy][dr]=max(nStep,step-nStep+);
  78. fx+=gx[dr];
  79. fy+=gy[dr];
  80. nStep++;
  81. }
  82. }
  83.  
  84. }
  85.  
  86. int farm() {
  87. int i,j;
  88. mz(b);
  89.  
  90. ///-
  91. FOR(i,,n) {
  92. gank(i,,);
  93. }
  94.  
  95. ///|
  96. FOR(i,,n) {
  97. gank(,i,);
  98. }
  99.  
  100. ///"/"
  101. FOR(i,,n) {
  102. gank(i,,);
  103. //printf("start at %d,%d:\n",n,i);
  104. gank(n,i,);
  105. }
  106.  
  107. ///"\"
  108. FOR(i,,n) {
  109. gank(i,,);
  110. gank(,i,);
  111. }
  112.  
  113. int ans=;
  114. FOR(i,,n) {
  115. FOR(j,,n) {
  116. //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]);
  117. ans=max(ans,b[i][j][]+b[i][j][]-);
  118. ans=max(ans,b[i][j][]+b[i][j][]-);
  119. }
  120. }
  121. return ans;
  122. }
  123.  
  124. int main() {
  125. int i,j;
  126. while(scanf("%d",&n)!=EOF) {
  127. if(n==)break;
  128. FOR(i,,n) {
  129. FOR(j,,n)scanf(" %c",&a[i][j]);
  130. }
  131.  
  132. // printf("\n%d\n",n);
  133. // FOR(i,1,n){
  134. // FOR(j,1,n)printf("%c",a[i][j]);
  135. // puts("");
  136. // }
  137. printf("%d\n",farm());
  138. }
  139. return ;
  140. }

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. 【uoj264】 NOIP2016—蚯蚓

    http://uoj.ac/problem/264 (题目链接) 题意 n条蚯蚓,时间为m.每单位时间要可以将最长的蚯蚓切成len/2和len-len/2两份,长度为0的蚯蚓不会消失,因为每单位时间所 ...

  2. Uva11464 Even Parity

    枚举每个格子的状态显然是不可能的. 思考发现,矩阵第一行的状态确定以后,下面的状态都可以递推出来. 于是状压枚举第一行的状态,递推全图的状态并判定是否可行. /*by SilverN*/ #inclu ...

  3. 用python虚拟串口

    在linux下调试串口程序,无奈下面的硬件还没到位,所以,想着自己模拟一个串口用用.试了下下面这段代码: #!/usr/bin/env python #coding=utf-8 import pty ...

  4. IDLE快捷键

    Ctrl + Space  完成类.方法.变量名称的自动输入,这个快捷键是我最经常使用的快捷键了,它可以完成类.方法.变量名称的自动录入,很方便.(不过在我的电脑上和输入法冲突) Ctrl + N 快 ...

  5. Linux 之 编译器 gcc/g++参数详解

    2016年12月9日16:48:53 ----------------------------- 内容目录: [介绍] gcc and g++分别是gnu的c & c++编译器 gcc/g++ ...

  6. 利用css3选择器及css3边框做出的特效(1)

    利用border-radius及box-shadow制作圆角表格 界面效果图如下: css样式如下所示: * { margin:; padding:; } body { padding: 40px 1 ...

  7. web前端开发修炼之道--编写高质量代码

    想想自己的页面实现是否糟糕 Web标准--结构.样式和行为的分离 Web标准可分为三个部分:结构标准.样式标准.行为标准. 结构标准包括XML标准.XHTML标准.HTML标准 样式标准主要是指的CS ...

  8. Ubuntu学习总结-08 Ubuntu运行Shell脚本报 shell /bin/bash^M: bad interpreter错误问题解决

    错误原因之一很有可能是运行的脚本文件是DOS格式的, 即每一行的行尾以\r\n来标识, 其ASCII码分别是0x0D, 0x0A.可以有很多种办法看这个文件是DOS格式的还是UNIX格式的, 还是MA ...

  9. RBAC权限设计实例

    http://blog.csdn.net/painsonline/article/details/7183629 实现业务系统中的用户权限管理 B/S系统中的权限比C/S中的更显的重要,C/S系统因为 ...

  10. IOS VFL屏幕自适应

    -(void)fun1{ //注意使用VFL,不用设置视图的frame UIView *view = [[UIView alloc] init]; view.backgroundColor = [UI ...