http://acm.hdu.edu.cn/showproblem.php?pid=5024

找到一个最长的L型,L可以是斜着的

简单的模拟

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
int n;
char s[115][115];
bool vis[115][115];
int dx[] = {1,-1,0,0,1,-1,1,-1},
dy[] = {0,0,1,-1,-1,-1,1,1};
bool in(int x,int y)
{
return 0 <= x && x < n && 0 <= y && y < n;
}
int find(int x,int y)
{ int ans = 0;
for(int i = 0;i < 8;++i)
for(int j = i+1;j < 8;++j)if(dx[i]*dx[j] + dy[i]*dy[j] == 0){
int xx = x + dx[i],yy = y + dy[i];
int x1 = x + dx[j],y1 = y + dy[j];
int res = 1;
while(in(xx,yy) && s[xx][yy] == '.'){
res++;
xx += dx[i];
yy += dy[i];
}
while(in(x1,y1) && s[x1][y1] == '.'){
res++;
x1 += dx[j];
y1 += dy[j];
}
ans = max(res,ans);
}
return ans;
}
int main(){
while(~RD(n) && n){
//clr0(vis);
for(int i = 0;i < n;++i){
scanf("%s",s[i]);
}
int mx = 0;
for(int i = 0;i < n;++i)
for(int j = 0;j < n;++j){
if(s[i][j] == '.'){
mx = max(mx,find(i,j));
}
}
printf("%d\n",mx);
}
return 0;
}

hdu 5024 最长的L型的更多相关文章

  1. 敏捷开发松结对编程系列:L型代码结构案例StatusFiltersDropdownList(中)

    这是松结对编程的第22篇(专栏目录). 接前文 业务代码 比较长,基本上就是看被注释隔开的三大段,先显示状态群筛选链接,然后是单个状态筛选,然后是显示下拉框的当前选中项,最后显示下拉框. public ...

  2. hdu 3308 最长连续上升区间

    LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  3. hdu 3068 最长回文 manacher算法(视频)

    感悟: 首先我要Orz一下qsc,我在网上很难找到关于acm的教学视频,但偶然发现了这个,感觉做的很好,链接:戳戳戳 感觉这种花费自己时间去教别人的人真的很伟大. manacher算法把所有的回文都变 ...

  4. hdu 3068 最长回文(manachar求最长回文子串)

    题目连接:hdu 3068 最长回文 解题思路:通过manachar算法求最长回文子串,如果用遍历的话绝对超时. #include <stdio.h> #include <strin ...

  5. L型代码结构案例:Link访问权限(上)

    这是松结对编程的第20篇(专栏目录). 本文探讨Link访问权限的最佳实现方法,力求外观干净且封装良好. 这些代码将位于L型代码结构(参见松结对编程系列中的定义)的下层,调用者无需理解其原理. 顺便说 ...

  6. HDU - 3068 最长回文(manacher)

    HDU - 3068 最长回文 Time Limit: 2000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Subm ...

  7. [数学] 将长为L的木棒随机折成3段,则3段构成三角形的概率

    1.题目 如题,将长为L的木棒随机折成3段,则3段构成三角形的概率是多少? 2.解析 这个与其说是编程题目,倒不如说是个数学题目.可能是你没有见过,或者没有过这种解题思想.(还是那句,一回生两回熟,类 ...

  8. hdu 4691 最长的共同前缀 后缀数组 +lcp+rmq

    http://acm.hdu.edu.cn/showproblem.php? pid=4691 去年夏天,更多的学校的种族称号.当时,没有后缀数组 今天将是,事实上,自己的后缀阵列组合rmq或到,但是 ...

  9. hdu 1950 最长上升子序列(lis) nlogn算法【dp】

    这个博客说的已经很好了.http://blog.csdn.net/shuangde800/article/details/7474903 简单记录一下自己学的: 问题就是求一个数列最长上升子序列的长度 ...

随机推荐

  1. session第二篇

    二 A.application对象 1.application对象实现了用户间数据的共享,可存放全局变量. 2.application对象开始于服务器的启动,终止于服务器的关闭. 3.在用户的前后连接 ...

  2. 树莓派Zero W GPIO控制

    作者:陈拓 chentuo@ms.xab.ac.cn 2018.06.09/2018.07.05 0.  概述 本文介绍树莓派 Zero W的GPIO控制,并用LED看效果. 0.1 树莓派GPIO编 ...

  3. HTML5 画图--文字

    1:html <div style="margin:0 auto;width:794px;height:1123px"> <canvas id="myC ...

  4. ubuntu16.04安装virtualbox

    download:download.virtualbox.org/virtualbox/5.0.10/virtualbox-5.0_5.0.10-104061~Ubuntu~trusty_amd64. ...

  5. Sorting(好题)

    Sorting https://www.zhixincode.com/contest/21/problem/I?problem_id=324 题目描述 你有一个数列a_1, a_2, \dots, a ...

  6. 平衡二叉树Balanced Binary Tree

    [抄题]: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced b ...

  7. [leetcode]632. Smallest Range最小范围

    You have k lists of sorted integers in ascending order. Find the smallest range that includes at lea ...

  8. 什么是Shell、Shell脚本

    Shell本身是一个用C语言编写的程序,它是用户使用Linux的桥梁.Shell既是一种命令语言,又是一种程序设计语言.作为命令语言,它交互式地解释和执行用户输入的命令:作为程序设计语言,它定义了各种 ...

  9. 5-分西瓜差最小(背包 || dfs)

    /*   zb立刻下定决心买了一堆西瓜.当他准备把西瓜送给C小加和never的时候,遇到了一个难题,never和C小加不在一块住,只能把西瓜分成两堆给他们,为了对每个人都公平,他想让两堆的重量之差最小 ...

  10. 使用Spring框架来管理模板类

    1. 刚才编写的代码使用的是new的方式,应该把这些类交给Spring框架来管理. 2. 修改的步骤如下 applicationContext.xml中<beans>标签的开头配置为: * ...