Wang Xifeng's Little Plot

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

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
2014 ACM/ICPC Asia Regional Guangzhou Online
Recommend
hujie

题目大意:在一个n*n的矩阵中,可以从任意一个‘.’出发,只能九十度拐弯一次,可以往八个方向走,只有'.'可以通过,最多可以通过几个'.' 解题思路:考虑到只能拐弯一次,所以上上下左右当作一组,把斜着走当作一组,每次从这两组中走的最远的两个方向相加求两组max,此时这就是该点能够走的最长路径,用dfs

#include<iostream>
#include<cstdio>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<climits>
#include<cmath>
#include<vector>
#include <bitset>
#include<algorithm>
#include <queue>
#include<map>
using namespace std;int dixx[5] = { 1,0,-1,0 };
int diyy[5] = { 0,1,0,-1 };
int dix[5] = { 1,1,-1,-1 };
int diy[5] = { 1,-1,1,-1 };
int a[5];
int b[5], n;
char tu[105][105];
int check(int x, int y,int j,int k)
{int ans = 0;ans++;if (tu[x + j][y + k] == '.')ans+=check(x + j, y + k, j, k);return ans;}
int dfs(int x, int y)
{int i;memset(a, 0, sizeof(a));memset(b, 0, sizeof(b));for (i = 0; i <4; i++){if (tu[x + dixx[i]][y + diyy[i]] == '.'){a[i] = check(x + dixx[i], y + diyy[i],dixx[i],diyy[i]);}if (tu[x + dix[i]][y + diy[i]] == '.'){b[i] = check(x + dix[i], y + diy[i],dix[i],diy[i]);}}sort(a, a + 4);sort(b, b + 4);return max(a[3] + a[2], b[3] + b[2]);
}
int main()
{int ans, i, j;for (;;){memset(tu, 0, sizeof(tu));cin >> n;if (n == 0) return 0;for (i = 1; i <= n; i++)for (j = 1; j <= n; j++)cin >> tu[i][j];ans = 0;for (i = 1; i <= n; i++){for (j = 1; j <= n; j++){if (tu[i][j] == '.'){ans=max(ans,dfs(i, j));}}}cout << ans+1 << endl;}
}

2014 ACM/ICPC Asia Regional Guangzhou Online C题Wang Xifeng's Little Plot(dfs)相关推荐

  1. 2014 ACM/ICPC Asia Regional Guangzhou Online Wang Xifeng's Little Plot HDU5024

    一道好枚举+模拟题目.转换思维视角 这道题是我做的,规模不大N<=100,以为正常DFS搜索,于是傻乎乎的写了起来.各种条件限制模拟过程 但仔细一分析发现对每个点进行全部八个方向的遍历100X1 ...

  2. hdu 5023 poj 2777(线段染色)2014 ACM/ICPC Asia Regional 广州 Online

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5023 http://poj.org/problem?id=2777 题意:给出一个长度为N的线段,分 ...

  3. 2014 ACM/ICPC Asia Regional Xi'an Online

    2014西安网络赛 A. Post Robot 把每种单词都kmp跑一遍,顺序输出即可 #include <cstdio> #include <iostream> #inclu ...

  4. 2014 ACM/ICPC Asia Regional Beijing Site

    1001 A Curious Matt 1002 Black And White 1003 Collision 1004 Dire Wolf 1005 Everlasting L 1006 Fluor ...

  5. Problem 1002-2017 ACM/ICPC Asia Regional Shenyang Online

    网络赛:2017 ACM/ICPC Asia Regional Shenyang Online 题目来源:cable cable cable Problem Description: Connecti ...

  6. 2015 ACM/ICPC Asia Regional Shenyang Online题解

    以下所有AC题解程序来自"仙客传奇"团队. AC题数:7/13 ABCFGJL A. Traversal AC的C++语言程序: #include <bits/stdc++. ...

  7. 2017 ACM ICPC Asia Regional - Daejeon

    2017 ACM ICPC Asia Regional - Daejeon Problem A Broadcast Stations 题目描述:给出一棵树,每一个点有一个辐射距离\(p_i\)(待确定 ...

  8. The 36th ACM/ICPC Asia Regional Dalian Site 1006 Dave

    Dave Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65768/65768K (Java/Other) Total Submissi ...

  9. 2013 ACM/ICPC Asia Regional Chengdu Online We Love MOE Girls 字符串STL 的应用

    题目来源: http://acm.hdu.edu.cn/showproblem.php?pid=4730 分析1:string s.substr(pos, n) 从 pos 开始 截取n个 字符 代码 ...

最新文章

  1. 圆环,扇形控件基本算法一种实现 - 代码库 - CocoaChina_让移动开发更简单
  2. java 区间树_线段树(区间树)之区间染色和4n推导过程
  3. 协议簇:IPv4 解析
  4. bash ./php-memcache.sh,PHP+shell脚本操作Memcached和Apache Status的实例分享
  5. 各地特色美食与点菜的艺术
  6. 面向对象3-析构函数和私有属性
  7. php session不可用,php session 使用与安全
  8. python从入门到实践课后答案-Python编程:从入门到实践(课后习题8)
  9. [Git]git教程
  10. 怎么调用html调色板,JS实现仿PS的调色板效果完整实例
  11. It is a distutils installed project and thus we cannot accurately determine which files belong to
  12. Gitlab用户角色权限Guest、Reporter、Developer、Master、Owner
  13. ArcGIS创建缓冲区并相交融合
  14. MT9630/9632 遥控器配置
  15. MySQL5.7 Attempted to use a closed or broken resource pool 处理过程
  16. 一篇文章带你了解python数据分析岗位怎么样
  17. 电饭煲电路原理图与解析
  18. 淘宝店铺订单解密接口/淘宝店铺订单插旗接口/淘宝店铺订单交易接口/淘宝店铺商品上传接口/淘宝店铺订单明文接口/代码对接分享
  19. 将汉字输入到计算机,一种将汉字输入计算机的方法
  20. 芯片封装形式一二三介绍

热门文章

  1. Mybatis plus 之 QueryWrapper、LambdaQueryWrapper、LambdaQueryChainWrapper
  2. 《信用管理》--信用评分方法之Z评分模型、ZETA评分模型
  3. 一篇《1984》的书评
  4. selenium中启动chrome浏览器时加载插件
  5. 设置应用内字体大小不跟随系统字体大小
  6. 华南师范大学计算机课网址,华南师范大学网络课程 首页
  7. nyoj-荷兰国旗问题
  8. 前端-HTML-web服务本质-HTTP协议-请求-标签-01(待完善)
  9. 如何用条码打印软件实现条码数据扫描后立即打印?
  10. 汇编DOSBox安装及其常见指令(附安装包)