题意:求一个图中只有一个90°拐点的路的最大长度。

分析:枚举每一个为‘.’的点,求出以该点为拐点的八种路中的最大长度,再比较所有点,得出最大长度即可。

如上样例,这样是个90°的角...

注意:最多只有一个拐点,但是通过枚举每一个点的方法,可以在枚举到一条没有拐点的路的端点处时计算出这条路的长度,所以不用特判平角的情况。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) a < b ? a : b
#define Max(a, b) a < b ? b : a
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {, , -, };
const int dc[] = {-, , , };
const double pi = acos(-1.0);
const double eps = 1e-;
const int MOD = 1e9 + ;
const int MAXN = + ;
const int MAXT = + ;
using namespace std;
char s[MAXN][MAXN];
int a[MAXN];
int N;
int solve(int a, int b){
int cnt[];
memset(cnt, , sizeof cnt);
for(int i = b - ; i >= ; --i){//从该点向左走
if(s[a][i] == '.') ++cnt[];
else break;
}
for(int i = a - , j = b - ; i >= && j >= ; --i, --j){//从该点向左上走,以下按顺时针依次求
if(s[i][j] == '.') ++cnt[];
else break;
}
for(int i = a - ; i >= ; --i){
if(s[i][b] == '.') ++cnt[];
else break;
}
for(int i = a - , j = b + ; i >= && j < N; --i, ++j){
if(s[i][j] == '.') ++cnt[];
else break;
}
for(int i = b + ; i < N; ++i){
if(s[a][i] == '.') ++cnt[];
else break;
}
for(int i = a + , j = b + ; i < N && j < N; ++i, ++j){
if(s[i][j] == '.') ++cnt[];
else break;
}
for(int i = a + ; i < N; ++i){
if(s[i][b] == '.') ++cnt[];
else break;
}
for(int i = a + , j = b - ; i < N && j >= ; ++i, --j){
if(s[i][j] == '.') ++cnt[];
else break;
}
int sum = ;
for(int i = ; i < ; ++i){
sum = Max(sum, cnt[i] + cnt[(i + ) % ] + );
}
return sum;
}
int main(){
while(scanf("%d", &N) == ){
if(N == ) return ;
memset(s, , sizeof s);
memset(a, , sizeof a);
for(int i = ; i < N; ++i){
scanf("%s", s[i]);
}
int cnt = ;
for(int i = ; i < N; ++i){
for(int j = ; j < N; ++j){
if(s[i][j] == '.'){
a[cnt++] = solve(i, j);
}
}
}
sort(a, a + cnt);
printf("%d\n", a[cnt - ]);
}
return ;
}

HDU 5024 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. [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 ...

  3. HDU 5024 Wang Xifeng&#39;s Little Plot 搜索

    pid=5024">点击打开链接 Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  4. 2014 网选 5024 Wang Xifeng's Little Plot

    题意:从任意一个任意一个可走的点开始找一个最长的路,这条路如果有转弯的话, 那么必须是 90度,或者没有转弯! 思路: 首先用dfs将所有可走点开始的 8 个方向上的线段的最长长度求出来 ! step ...

  5. hdu5024 Wang Xifeng's Little Plot (水

    http://acm.hdu.edu.cn/showproblem.php?pid=5024 网络赛 Wang Xifeng's Little Plot Time Limit: 2000/1000 M ...

  6. hdu 5024 最长的L型

    http://acm.hdu.edu.cn/showproblem.php?pid=5024 找到一个最长的L型,L可以是斜着的 简单的模拟 #include <cstdio> #incl ...

  7. HDU 4173 Party Location(计算几何,枚举)

    HDU 4173 题意:已知n(n<=200)位參赛选手的住所坐标.现要邀请尽可能多的选手来參加一个party,而每一个选手对于离住所超过2.5Km的party一律不去,求最多能够有多少个选手去 ...

  8. HDU 5944 Fxx and string(暴力/枚举)

    传送门 Fxx and string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Othe ...

  9. HDU 4282 A very hard mathematic problem --枚举+二分(或不加)

    题意:问方程X^Z + Y^Z + XYZ = K (X<Y,Z>1)有多少个正整数解 (K<2^31) 解法:看K不大,而且不难看出 Z<=30, X<=sqrt(K) ...

随机推荐

  1. plupload上传插件在SpringMVC中的整合

    前言:近期在给学院的站点做一个加入附件的功能,首先到了某某邮箱看了一下.简单有用.可是是flash做的,无法拷贝.就仅仅好上网找插件了.经过筛选.最终找到plupload这款插件(其实有的编辑器自带加 ...

  2. You don't have permission to access / on this server

    配置虚拟主机的时候,里面加上如下: <Directory "/var/www/html"> Options Indexes FollowSymLinks AllowOv ...

  3. Perl的DATA文件句柄

    有太多次写完一个perl程序,需要另外新建一个文件来测试,每次觉得很繁琐,但又不得不这么做.没想到原来perl已经提供了解决方案,这就是DATA. 使用很简单,见下面这个例子: #!/usr/bin/ ...

  4. MySQL执行SHOW STATUS查询服务器状态状态之Handler_read_* 详解

    在MySQL里,我们一般使用SHOW STATUS查询服务器状态,语法一般来说如下: SHOW [GLOBAL | SESSION] STATUS [LIKE ‘pattern’ | WHERE ex ...

  5. VSS错误:The Sourcesafe Web service cannot be accessed at the specified address

    第一次使用正常,今天再次打开vs项目的时候就突然连不上vss的服务器了.       手动修改连接的时候会让输入一个address(http的) (一般正常的连接会是浏览的方式找到服务器文件的地址的) ...

  6. JS后退, JS返回上一页, JS返回下一页

    Javascript 返回上一页: 1. history.go(-1), 返回两个页面: history.go(-2); 2. history.back(). 3. window.history.fo ...

  7. dp与px之间的转换

    代码如下: package com.example.fxvideo.utils; import android.content.Context; public class DensityUtils { ...

  8. 通过UIBezierPath贝塞尔曲线画圆形、椭圆、矩形

    /**创建椭圆形的贝塞尔曲线*/ UIBezierPath *_ovalPath=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(, , , )]; ...

  9. 自己调用NTDLL函数

    一.概述 在DLL初始化的时候有时不能调用其它系统DLL的函数,以免导致问题,但有时候又必须要调用怎么办?一种办法就是自己直接调用NTDLL接口,这样肯定没有问题. 下面我写个自己调用Registry ...

  10. 【Python Lib】解析HTML利器 BeautifulSoup

    - - 官方API文档,中文版 http://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html - 以后会把常用的摘录出来