HDU 5024
题目大意:
在2个图上显示为'.'的位置建两座房间,保证这两间房子中间只转一个90度的弯,可以斜着走,问能建成房子的最远的路程长度为多少
暴力枚举
因为有8个方向,但横竖走和斜着走是不会产生90度角的,所以分成两部分进行考虑,每次找到一个联通的点作为转角,朝四个方向不断扩展长度,直到不能扩展为止,把最长长度的两个方向上的长度相加得到那一个点作为转角的最值
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 102
char mat[N][N];
int maxn,n;
int dir1[][] = {{,},{-,},{,},{,-}};
int dir2[][] = {{,},{-,},{,-},{-,-}};
void solve1(int x,int y)
{
int tmp[];
for(int i=;i<;i++){
int xx=x,yy=y;
tmp[i]=;
while(true){
xx+=dir1[i][];
yy+=dir1[i][];
if(mat[xx][yy]!='#'&&xx>=&&xx<n&&yy>=&&yy<n){
tmp[i]++;
}
else break;
}
}
sort(tmp,tmp+);
maxn = max(maxn,tmp[]+tmp[]);
} void solve2(int x,int y)
{
int tmp[]; for(int i=;i<;i++){
int xx=x,yy=y;
tmp[i]=;
while(true){
xx+=dir2[i][];
yy+=dir2[i][];
if(mat[xx][yy]!='#'&&xx>=&&xx<n&&yy>=&&yy<n){
tmp[i]++;
}
else break;
}
//if(x==0&&y==1) cout<<i<<" "<<tmp[i]<<endl;
}
sort(tmp,tmp+);
maxn = max(maxn,tmp[]+tmp[]);
} int main()
{
while(~scanf("%d",&n)){
if(n==)
break; maxn = ; for(int i=;i<n;i++)
for(int j=;j<n;j++)
cin>>mat[i][j]; for(int i=;i<n;i++)
for(int j=;j<n;j++)
if(mat[i][j]!='#'){
solve1(i,j); solve2(i,j); } printf("%d\n",maxn+);
}
return ;
}
HDU 5024的更多相关文章
- hdu 5024 最长的L型
http://acm.hdu.edu.cn/showproblem.php?pid=5024 找到一个最长的L型,L可以是斜着的 简单的模拟 #include <cstdio> #incl ...
- HDU 5024 Wang Xifeng's Little Plot 搜索
pid=5024">点击打开链接 Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDU 5024 Wang Xifeng's Little Plot (DP)
题意:给定一个n*m的矩阵,#表示不能走,.表示能走,让你求出最长的一条路,并且最多拐弯一次且为90度. 析:DP,dp[i][j][k][d] 表示当前在(i, j)位置,第 k 个方向,转了 d ...
- HDU 5024 Wang Xifeng's Little Plot(枚举)
题意:求一个图中只有一个90°拐点的路的最大长度. 分析:枚举每一个为'.'的点,求出以该点为拐点的八种路中的最大长度,再比较所有点,得出最大长度即可. 如上样例,这样是个90°的角... 注意:最多 ...
- [ACM] HDU 5024 Wang Xifeng's Little Plot (构造,枚举)
Wang Xifeng's Little Plot Problem Description <Dream of the Red Chamber>(also <The Story of ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- B - Archer
Problem description SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to ...
- 32位Oracle10g在64位CentOS下安装失败记录
环境信息:Alibaba Cloud Elastic Compute Service,CentOS Linux release 7.4.1708 (Core),16C/64GB. 使用32位Oracl ...
- 【LeetCode】树的遍历
非递归中序遍历: 思路:注释 vector<int> inorderTraversal(TreeNode* root) { vector<int>ret; if(root == ...
- php中除法取整的方法(round,ceil,floor)
PHP中遇到需要将除法所得结果取整的情况时,就需要用到以下方法: 1. round:四舍五入 round() 函数对浮点数进行四舍五入. 语法:round(x, prec) 参数 描述 x 可选.规定 ...
- 7.JAVA-类继承、覆写、final关键字
1.JAVA继承-extends 在java中,要想实现继承则使用extends关键字. 一般子类被称为派生类,父类称为基类(super) extends需要注意的地方: java不允许多重继承(一个 ...
- pickle序列化与反序列化 + eval说明
import pickle # #1.从文件中读取pickle格式with open('egon.json','rb') as f: pkl=f.read()#2.将json_str转成内存中的数据类 ...
- 升级 Cocoapods 到1.2.0指定版本,降低版本及卸载
=====================升级版本=================== CocoaPods 1.1.0+ is required to build SnapKit 3.0.0+. 在 ...
- iOS programming Code Snippet Library
iOS programming Code Snippet Library The freebie code comes from the code snippet library. 代码来自cod ...
- python学习一 hello world of python
我使用的环境是 OS:Red Hat Enterprise Linux AS release 4 (Nahant Update 3) PYTHON:2.7.2 如果操作系统没有安装python, 百度 ...
- linux centos7 tomcat8 配置成服务启动
1. tomact 解压到/usr/local/tomcat下 2.vim /usr/local/tomcat/bin/catalina.sh 在OS specific support.前加上 (注意 ...