题意:求一个图中只有一个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. oc-23-static

    #import <Foundation/Foundation.h> #import "Person.h" int main(int argc, const char * ...

  2. RosettaNet

    RosettaNet 这一名字源自于 1799 年在埃及发现的 Rosetta Stone .这要追溯到公元前 196 年,该石头是在 Rosetta (Rashid) 镇附近被人发现的,上面用两种不 ...

  3. C#生成DBF文件

    C# 生成DBF,无需注册Microsoft.Jet.OLEDB. namespace ConsoleApplication { class Program { static void Main(st ...

  4. Java学习笔记——内部类及其调用方法

    一.static内部类的static方法 public class Test0719_Inner_Test { public static void main(String[] args) { //s ...

  5. 重构4-Push Down Method(方法下移)

    我们介绍了将方法迁移到基类以供多个子类使用的上移方法重构,今天我们来看看相反的操作.重构前的代码如下: public abstract class Animal { public void Bark( ...

  6. String类的方法2

    ---恢复内容开始--- .ToLower()    //转为小写字符串"AbC"-->"abc" .ToUpper()    //转为大写"A ...

  7. JavaScript 键盘event.keyCode值列表大全

      JavaScript 键盘event.keyCode值列表大全   event.keyCode值列表大全,对于需要根据键盘按键触发相应事件的朋友需要. 网上收集的KeyCode值方便大家查找: k ...

  8. 2014年互联网IT待遇【转载】

    2014年互联网IT待遇[转载] 一.民企 1.百度 13k*14.6,special 14~17k*14.6 开发类 13K*14.6    (2014) 测试类.前端类 12K*14.6    ( ...

  9. hdu 4739 状压DP

    这里有状态压缩DP的好博文 题目:题目比较神,自己看题目吧 分析: 大概有两种思路: 1.dfs,判断正方形的话可以通过枚举对角线,大概每次减少4个三角形,加上一些小剪枝的话可以过. 2.状压DP,先 ...

  10. 数据库自定义表值函数Split(@LongStr, @SplitStr, @IsDistinct )

    CREATE FUNCTION [dbo].[F3_Split](@LongStr VARCHAR(MAX),@SplitStr VARCHAR(100),@IsDistinct BIT)RETURN ...