Description

It is always very nice to have little brothers or sisters. You can tease them, lock them in the bathroom or put red hot chili in their sandwiches. But there is also a time when all meanness comes back!

As you know, in one month it is Christmas and this year you are honored to make the big star that will be stuck on the top of the Christmas tree. But when you get the triangle-patterned silver paper you realize that there are many holes in it. Your little sister has already cut out smaller triangles for the normal Christmas stars. Your only chance is to find an algorithm that tells you for each piece of silver paper the size of the largest remaining triangle.

Given a triangle structure with white and black fields inside you must find the largest triangle area of white fields, as shown in the following figure. 

Input

The input contains several triangle descriptions. The first line of each description contains an integer n (1 <= n <= 100), which gives the height of the triangle. The next n lines contain characters of the set {space, #, -} representing the rows of the triangle, where `#' is a black and `-' a white field. The spaces are used only to keep the triangle shape in the input by padding at the left end of the lines. (Compare with the sample input. The first test case corresponds to the figure.) 
For each triangle, the number of the characters `#' and `-' per line is odd and decreases from 2n - 1 down to 1.

The input is terminated by a description starting with n = 0. 

Output

For each triangle in the input, first output the number of the triangle, as shown in the sample output. Then print the line "The largest triangle area is a.", where a is the number of fields inside the largest triangle that consists only of white fields. Note that the largest triangle can have its point at the top, as in the second case of the sample input.

Output a blank line after each test case.

Sample Input

5
#-##----#
-----#-
---#-
-#-
-
4
#-#-#--
#---#
##-
-
0

Sample Output

Triangle #1
The largest triangle area is 9. Triangle #2
The largest triangle area is 4.

题目意思是:给你一个高为n的三角形,其中#表示黑色,-表示白色,问这个里面最大的3角形的面积(其中每个小的3角形面积为1)。算法其实很简单,就是遍历每一个白色小三角形,如果它是朝上的(行列相加为奇数)就把它看为最大三角形的顶部,向下逐层搜索,看最大能为几层;同理当其朝下时,就逐层向上搜索,求最大层。然后用maxNum维护一个最终的最大层(注意这个数最好初始化为0!!!)。将输入3角形转换为从(1,1)开始的0-1矩阵(这样可以省去边界处理),要注意数组要开的大一点!!!

 #include<iostream>
#include<string>
#include<string.h>
#include<cstring>
using namespace std;
int n,tab[][];
int proNum,maxNum;
bool lu(int I,int J){//向上找
for(int i=;i<*proNum+;i++)
if(!tab[I-proNum][J-proNum+i])return ;
return ;
}
bool ld(int I,int J){//向下找
for(int i=;i<*proNum+;i++)
if(!tab[I+proNum][J-proNum+i])return ;
return ;
}
void dfs(int I,int J){
if((I+J)%==){//朝下,向上找
while(lu(I,J)){
proNum++;
}
}else{//朝上,向下找
while(ld(I,J)){
proNum++;
}
}
}
void solve(){
maxNum=;//初始为0(针对全黑情况)
for(int i=;i<=n;i++){
for(int j=i;j<=*n-i;j++){
if(tab[i][j]){//尝试将所有白三角形当成顶点看其最大层数
proNum=;
dfs(i,j);
if(proNum>maxNum)maxNum=proNum;//更新
}
}
}
}
int main(){
string str;int casee=;
while(cin>>n && n){
memset(tab,,sizeof(tab));
for(int i=;i<=n;i++){
cin>>str;
for(int j=;j<str.size();j++){
if(str[j]=='-')tab[i][j+i]=;
}
}
solve();
cout<<"Triangle #"<<casee++<<'\n';
cout<<"The largest triangle area is "<<maxNum*maxNum<<".\n\n";
}return ; }

[ACM_搜索] Triangles(POJ1471,简单搜索,注意细节)的更多相关文章

  1. 搜索入门_简单搜索bfs dfs大杂烩

    dfs题大杂烩 棋盘问题  POJ - 1321 和经典的八皇后问题一样.  给你一个棋盘,只有#区域可以放棋子,同时同一行和同一列只能有一个棋子. 问你放k个棋子有多少种方案. 很明显,这是搜索题. ...

  2. 《ElasticSearch6.x实战教程》之简单搜索、Java客户端(上)

    第五章-简单搜索 众里寻他千百度 搜索是ES的核心,本节讲解一些基本的简单的搜索. 掌握ES搜索查询的RESTful的API犹如掌握关系型数据库的SQL语句,尽管Java客户端API为我们不需要我们去 ...

  3. ElasticSearch 5学习(4)——简单搜索笔记

    空搜索: GET /_search hits: total 总数 hits 前10条数据 hits 数组中的每个结果都包含_index._type和文档的_id字段,被加入到_source字段中这意味 ...

  4. [转载]SharePoint 2013搜索学习笔记之搜索构架简单概述

    Sharepoint搜索引擎主要由6种组件构成,他们分别是爬网组件,内容处理组件,分析处理组件,索引组件,查询处理组件,搜索管理组件.可以将这6种组件分别部署到Sharepoint场内的多个服务器上, ...

  5. nyoj 284 坦克大战 简单搜索

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=284 题意:在一个给定图中,铁墙,河流不可走,砖墙走的话,多花费时间1,问从起点到终点至少 ...

  6. 简单搜索dfs, 简单的修剪搜索

    选择最合适的语言做一个项目是非常重要的.但,熟练的掌握自己的武器,这也是非常重要的. ========================================================= ...

  7. 分布式搜索ElasticSearch构建集群与简单搜索实例应用

    分布式搜索ElasticSearch构建集群与简单搜索实例应用 关于ElasticSearch不介绍了,直接说应用. 分布式ElasticSearch集群构建的方法. 1.通过在程序中创建一个嵌入es ...

  8. 深度优先搜索DFS和广度优先搜索BFS简单解析(新手向)

    深度优先搜索DFS和广度优先搜索BFS简单解析 与树的遍历类似,图的遍历要求从某一点出发,每个点仅被访问一次,这个过程就是图的遍历.图的遍历常用的有深度优先搜索和广度优先搜索,这两者对于有向图和无向图 ...

  9. js算法初窥03(简单搜索及去重算法)

    前面我们了解了一些常用的排序算法,那么这篇文章我们来看看搜索算法的一些简单实现,我们先来介绍一个我们在实际工作中一定用到过的搜索算法--顺序搜索. 1.顺序搜索 其实顺序搜索十分简单,我们还是以第一篇 ...

随机推荐

  1. {Reship}{ListView}C# ListView用法详解

    ======================================================================== This aritcle came from http ...

  2. BSF、BSR: 位扫描指令

    ;BSF(Bit Scan Forward): 位扫描找1, 低 -> 高 ;BSR(Bit Scan Reverse): 位扫描找1, 高 -> 低   找到是 1 的位后, 把位置数给 ...

  3. Maven-3.2.2安装配置

    (1)安装JDK,这里是1.7.0_51 (2)Maven-3.2.2下载地址:http://mirrors.cnnic.cn/apache/maven/maven-3/3.2.2/binaries/ ...

  4. Ubuntu下shell脚本运行异常:bash和dash的区别

    Ubuntu下我用bash到语法写了一个shell脚本(准确的说是把书上的脚本敲进电脑),在ubuntu下,用sh test.sh来运行,但是出现了意料之外到结果,比如echo -e "\n ...

  5. log4net注意事项

    log4net的配置信息可以直接配置在系统的配置文件中,也可以单独写一个配置文件,文件名随便起,如log4net.config,单独的文件属性“复制到输出目录”应该是true.因为log4net框架会 ...

  6. Selenium2+python自动化8-SeleniumBuilder辅助定位元素

    前言 福利来了,对于用火狐浏览器的小伙伴们,你还在为定位元素而烦恼嘛? 上古神器Selenium Builder来啦,哪里不会点哪里,妈妈再也不用担心我的定位元素问题啦!(但是也不是万能,基本上都能覆 ...

  7. 开源PLM软件Aras详解五 如何让ItemType显示在TOC上

    通过上一边ItemType我们大概了解,那么如何让ItemType显示在左侧的菜单上呢,又如何设置增删查改的权限呢,接下来将为演示. 在上一篇中,我们知道了ItemType的结构图,如下图 那么如何让 ...

  8. ZT 第一范式,第二范式,第三范式

    第一范式,第二范式,第三范式 Posted on 2012-05-09 16:30 GISerYang 阅读(6472) 评论(0) 编辑 收藏 第一范式 存在非主属性对码的部分依赖关系 R(A,B, ...

  9. Shi-Tomasi角点检测

    代码示例: #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #inc ...

  10. 移动端布局,div按比例布局,宽度为百分比,高度和宽度一样,即让div为正方形

    http://codepen.io/airen/details/XbVBZo <div><span>1</span></div> <div> ...