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): 264    Accepted Submission(s): 172

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

解题思路:

题目说迷宫行走的时候最多可以转一个九十度的角,又因为只要是能有90度角,拐肯定比不拐距离长,因此我枚举每一个点然后从该点出发的每一对直角,然后直角两端沿直线方向搜索就行了,整个过程取最大的步数。

#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;int n,num,sum[10],maxx;
char a[105][105];
int point[8][2]= {{0,1},{1,0},{0,-1},{-1,0},{-1,-1},{1,1},{1,-1},{-1,1}};bool judge(int x,int y)
{if(x<n&&x>=0&&y<n&&y>=0)return true;return false;
}void dfs(int x,int y,int t)
{int xx=x+point[t][0];int yy=y+point[t][1];if(a[xx][yy]=='.'&&judge(xx,yy)){dfs(xx,yy,t);num++;}
}void bfs(int x,int y)
{for(int i=0; i<8; i++){int xx=x+point[i][0];int yy=y+point[i][1];if(a[xx][yy]=='.'&&judge(xx,yy)){num=1;dfs(xx,yy,i);sum[i]=num;}}/*for(int i=0;i<n;i++)printf("%d ",sum[i]);printf("\n");*/maxx=max(maxx,sum[0]+sum[1]);maxx=max(maxx,sum[1]+sum[2]);maxx=max(maxx,sum[2]+sum[3]);maxx=max(maxx,sum[3]+sum[0]);maxx=max(maxx,sum[4]+sum[6]);maxx=max(maxx,sum[7]+sum[5]);maxx=max(maxx,sum[4]+sum[7]);maxx=max(maxx,sum[6]+sum[5]);
}int main()
{while(~scanf("%d%*c",&n)){if(n==0)break;for(int i=0; i<n; i++)scanf("%s",a[i]);maxx=-1;for(int i=0; i<n; i++)for(int j=0; j<n; j++){memset(sum,0,sizeof(sum));if(a[i][j]=='.')bfs(i,j);}printf("%d\n",maxx+1);}return 0;
}

2014广州网络赛1003||hdu 5024 搜索相关推荐

  1. 2019CCPC网络赛 1002 HDU 6703(权值线段树)

    2019CCPC网络赛 1002 HDU 6703(权值线段树) 思路:用权值线段树存题目给的数据后,2操作就是求权值线段树中大于等于k的部分中,靠近左端点的第一个大于r的值(这个求出来的只是原序列中 ...

  2. HDU 5025 Saving Tang Monk(广州网络赛D题)

    HDU 5025 Saving Tang Monk 题目链接 思路:记忆化广搜,vis[x][y][k][s]表示在x, y结点,有k把钥匙了,蛇剩余状态为s的步数,先把图预处理出来,然后进行广搜即可 ...

  3. hdu 5131 (2014广州现场赛 E题)

    题意:对给出的好汉按杀敌数从大到小排序,若相等,按字典序排.M个询问,询问名字输出对应的主排名和次排名.(排序之后)主排名是在该名字前比他杀敌数多的人的个数加1,次排名是该名字前和他杀敌数相等的人的个 ...

  4. 2017ccps网络赛 1003 Friend-Graph(暴力)HDU 6152

    题目描述 就是一个团队如果存在三个或者三个以上的人互为朋友的关系,或者都不是朋友的关系,那么就说明这个团队是一个坏团队,否则输出好团队. 解题思路 数据不大,暴力大法好,将每个人之间的关系都存于一个w ...

  5. 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)

    /* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> 2 #include<cst ...

  6. 沈阳网赛1003 HDU 5894 hannnnah_j’s Biological Test

    考虑每两个人之间隔了几把椅子.可以发现,一共有m个数,和为n-m,且每个数都>=k.将每个数都减去k-1,即得到:m个正数之和为n-k*m,方案数为C(n-k*m-1,m-1).需要乘以圆排列的 ...

  7. 2014 ACM/ICPC 北京赛区网络赛解题报告汇总

    首页 算法竞赛» 信息聚合 ONLINE JUDGE 书刊杂志 BLOG» 新闻故事» 招聘信息» 投稿须知 2014 ACM/ICPC 北京赛区网络赛解题报告汇总 九月 21st, 2014 | P ...

  8. ACM练级日志:HDU 4735(ACM 成都网络赛) 重复覆盖与DLX

    今天费了一下午+一晚上的劲,终于把重复覆盖问题给解决了.作为这算法的牺牲品的就是成都网络赛让我知道DLX这东西存在的那道题,HDU 4735.这也是第一次尝试独立对问题构造矩阵然后调用DLX得出结果的 ...

  9. ZOJ 3810 A Volcanic Island (2014年牡丹江赛区网络赛B题)

    ZOJ 3810 A Volcanic Island (2014年牡丹江赛区网络赛B题) 1.题目描写叙述:点击打开链接 2.解题思路:本题是四色定理的模板题.只是有几种情况要提前特判一下:n==1直 ...

最新文章

  1. BeanShell变量的基本范围
  2. php iso8601 gmt,如何使用PHP以iso 8601格式顯示日期
  3. 如何在10亿个整数中找出前1000个最大的数(TopN算法)
  4. Enum、Stream
  5. 使用tableView崩溃
  6. Layer下拉框监听
  7. python selenium打开新窗口,python selenium click打开新窗口
  8. Unity游戏ugui适配阿拉伯文本显示
  9. WPS安装自定义项安装程序出错问题
  10. iTextSharp 列表
  11. 高通MSM8953处理器(CPU)/骁龙625资料介绍
  12. 结构力学分析属于计算机哪类应用,结构力学 课堂笔记 (大学期末复习资料).doc...
  13. PCL(Point Cloud Library)学习指南资料推荐(2021版)
  14. C、C++、java的区别
  15. opencv中使用摄像头录制视频
  16. java中文转换工具类
  17. AIX smit设置设置能够输入中文
  18. 三亚自由行攻略(自己穷游总结)
  19. 什么是继承 继承的好处
  20. NKOJ 3762 守夜人 (并查集)

热门文章

  1. 【flowable】十、flowable网关
  2. 公司内网批量安装python依赖包
  3. openssl_decrypt解码空白字符处理方式
  4. 专访lan哥:大龄奶爸学竞赛
  5. 为了不在赎金信中暴露字迹,从杂志上搜索各个需要的字母,组成单词来表达意思.
  6. 不属于简历撰写技巧原则的是_撰写有效的技术简历的7个技巧
  7. Smark.Data 功能强大又灵活的Expression
  8. 1-范数、2-范数、∞-范数、F-范数,向量范数与矩阵范数
  9. otg和充电共用问题
  10. 各式各样的编程风格 ~~~