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) ...
随机推荐
- PHPDoc/PHPDocumentor生成API文档
PHPDocumentor是一个用PHP写的强大的文档自动生成工具,对于有规范注释的php程序,能够快速生成具有结构清晰.相互参照.索引等功能的API文档.旧版本是PHPDoc,PHPDoc是PEAR ...
- Squish License
https://www.froglogic.com/squish/gui-testing/prices-and-licensing/index.php Prices and Licensing Who ...
- 2dx关于js响应layer触摸消息的bug
cocos2dx关于js响应layer触摸消息的bug cocos2d-x 3.7 问题描述: 目前这个版本中(3.7),c++层的layer触摸消息只能通过消息的方式发送给js,不能像lua一样直接 ...
- 【阿里云产品公测】云引擎ACE -discuz安装
作者:阿里云用户云想未来 谢谢支持.为什么写的比较简单就是为方便新手谁想要很麻烦?亲测按这个教程可以安装成功!时间紧迫不发图片了纯原创 排版您请谅解 进入创建新应用的信息填写界面,此处需要填写一个赠送 ...
- 百度地图开发之poi检索,线路规划
官方文档 http://lbsyun.baidu.com/index.php?title=androidsdk/guide/key 先去官方文档申请秘钥下载压缩文件等操作,参考 百度地图的秘钥申请 ...
- about tomcat ssl
http://www.kuqin.com/shuoit/20140615/340573.html 1SSL单向认证概念 当客户端(服务请求方)向服务端(服务提供方)发起请求时,服务器端需要向客户端提供 ...
- localStorage的跨与实现方案
实现原理: HTML5 的 postMessage 为解决跨域页面通信提供了一套可控的机制, 而 localStorage 则提供了易用简洁的本地存储方案? 这两者结合起来,能否实现跨域的本地存储呢 ...
- hdu1331 按着题目的公式直接写
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #d ...
- Oracle数据库作业-6 查询成绩比该课程平均成绩低的同学的成绩表
33. 查询成绩比该课程平均成绩低的同学的成绩表. select * from score a where a.degree between 0 and( select avg(degree) fro ...
- 兼容性调试-- 在谷歌浏览器中,td 设置colspan的失效的问题
通过设置table width="100%"table-layout="fixed" 解决