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 ...
随机推荐
- 思维题 Gym 100553A Alter Board
题目传送门 /* 题意:一个n×m的矩形,相邻的颜色不同,黑或白.问最少的翻转次数,每次翻转可指定任意一个子矩形 思维题:最少要把偶数行和列翻转,也就是n/2+m/2次 */ #include < ...
- Android偏好设置(3)启动偏好设置后显示的界面PreferenceActivity和PreferenceFragment
Creating a Preference Activity To display your settings in an activity, extend the PreferenceActivit ...
- android开发学习——Mina框架
Apache Mina Server 是一个网络通信应用框架,对socket进行了封装. http://www.cnblogs.com/moonandstar08/p/5475766.html htt ...
- AJPFX解析Java关键字之assert
Java有许多关键字,但是这个关键字估计很少有人了解,今天就跟大家谈一谈这个关键字吧. 先说明一下,这个关键字开发中用的极少,感兴趣的朋友可以了解一下. 一.概述 在C和C++语言中都有assert关 ...
- LN : leetcode 646 Maximum Length of Pair Chain
lc 646 Maximum Length of Pair Chain 646 Maximum Length of Pair Chain You are given n pairs of number ...
- vue报错-Error: Cannot find module '@babel/core'
vue之webpack实战的时候遇到报错,Error: Cannot find module '@babel/core' 这报错,我百度了很久,后来发现报错里面有提示,发现是我的 babel-load ...
- js控制页面跳转,清缓存,强制刷新页面
单看标题,必定满脸蒙13. 其实,想表达的仅仅是,在js中通过window.location.href控制页面跳转时,有时会跳转至缓存页面,并没有真正去请求要跳转的地址,导致页面数据未能及时加载刷新. ...
- MySQL 中去重 distinct 用法
在使用MySQL时,有时需要查询出某个字段不重复的记录,这时可以使用mysql提供的distinct这个关键字来过滤重复的记录,但是实际中我们往往用distinct来返回不重复字段的条数(count( ...
- 输出所有进程和进程ID
#include <windows.h> #include <tlhelp32.h> #include <tchar.h> #include <stdio.h ...
- Java中List集合的遍历
一.对List的遍历有三种方式 List<String> list = new ArrayList<String>(); list.add("testone" ...