HDU 5024 Wang Xifeng's Little Plot(枚举)
题意:求一个图中只有一个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(枚举)的更多相关文章
- HDU 5024 Wang Xifeng's Little Plot (DP)
题意:给定一个n*m的矩阵,#表示不能走,.表示能走,让你求出最长的一条路,并且最多拐弯一次且为90度. 析:DP,dp[i][j][k][d] 表示当前在(i, j)位置,第 k 个方向,转了 d ...
- [ACM] HDU 5024 Wang Xifeng's Little Plot (构造,枚举)
Wang Xifeng's Little Plot Problem Description <Dream of the Red Chamber>(also <The Story of ...
- HDU 5024 Wang Xifeng's Little Plot 搜索
pid=5024">点击打开链接 Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others) Memory ...
- 2014 网选 5024 Wang Xifeng's Little Plot
题意:从任意一个任意一个可走的点开始找一个最长的路,这条路如果有转弯的话, 那么必须是 90度,或者没有转弯! 思路: 首先用dfs将所有可走点开始的 8 个方向上的线段的最长长度求出来 ! step ...
- 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 ...
- hdu 5024 最长的L型
http://acm.hdu.edu.cn/showproblem.php?pid=5024 找到一个最长的L型,L可以是斜着的 简单的模拟 #include <cstdio> #incl ...
- HDU 4173 Party Location(计算几何,枚举)
HDU 4173 题意:已知n(n<=200)位參赛选手的住所坐标.现要邀请尽可能多的选手来參加一个party,而每一个选手对于离住所超过2.5Km的party一律不去,求最多能够有多少个选手去 ...
- HDU 5944 Fxx and string(暴力/枚举)
传送门 Fxx and string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Othe ...
- 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) ...
随机推荐
- Ambari源代码分析之总览
一.基本概念: Resource:Ambari把能够被管理的资源的抽象为一个Resource实例,资源能够包括服务.组件.主机节点等,一个resource实例中包括了一系列该资源的属性: Proper ...
- boost.asio源码剖析
一. 前 言二. 架构浅析三. 流程分析 * 常见流程分析之一(Tcp异步连接) * 常见流程分析之二(Tcp异步接受连接) * 常见流程分析之三(Tcp异步读写数据) ...
- C# Socket基础(一)之启动异步服务监听
本文主要是以代码为主..NET技术交流群 199281001 .欢迎加入. //通知一个或多个正在等待的线程已发生事件. ManualResetEvent manager = new ManualRe ...
- 第1章 游戏之乐——让CPU占用率曲线听你指挥
让CPU占用率曲线听你指挥 写一个程序,让用于来决定Windows任务管理器(Task Manager)的CPU占用率.程序越精简越好,计算机语言不限.例如,可以实现下面三种情况: CPU的占用率固定 ...
- Linux下校验下载文件的完整性(MD5,SHA1,PGP)
查看: Linux下校验下载文件的完整性(MD5,SHA1,PGP) http://blog.useasp.net/archive/2014/03/29/use-md5-sha1-or-pgp-to- ...
- scala的下划线
1.作为“通配符”,类似Java中的*.如import scala.math._ 2.:_*作为一个整体,告诉编译器你希望将某个参数当作参数序列处理!例如val s = sum(1 to 5:_*)就 ...
- hadoop中hbase出现的问题
在安装hbase中出现问题如下: ERROR: Can't get master address from ZooKeeper; znode data == null 解决办法: 1.删除nameno ...
- [置顶] 《算法导论》习题解答搬运&&学习笔记 索引目录
开始学习<算法导论>了,虽然是本大部头,可能很难一下子看完,我还是会慢慢地研究的. 课后的习题和思考有些是很有挑战性的题目,我等蒻菜很难独立解决. 然后发现了Google上有挺全的algo ...
- React Native学习-measure测量view的宽高值
measure()测量是根据view标签中的ref属性,使用方法如下: measureWatermarkerImage(){ this.refs.watermarkerImage.measure((a ...
- HDU 1598 find the most comfortable road (MST)
find the most comfortable road Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d ...