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. 根据Excel线程句柄得到ID并且关闭进程

    [System.Runtime.InteropServices.DllImport("User32.dll", CharSet = System.Runtime.InteropSe ...

  2. 在C#中创建和读取XML文件

    1.创建简单的XML文件 为了便于测试,我们首先创建控制台应用程序,项目命名为CreateXml,Program.cs代码如下: 这样会在C盘根目录下创建data2.xml文件,文件内容为 using ...

  3. C#的 构造函数 和 方法重载

    构造函数(一本正经的讲构造函数 如果想看不正经的往下翻看方法重载) 方法名称与类名相同,没有返回值类型,连void都没有 用作给类的对象初始化 一个类中可以有多个构造 如果手动添加一个构造,系统不会自 ...

  4. quartus ii13.0~16.0 调用uedit (转载http://blog.sina.com.cn/s/blog_6d5560f00102vax6.html)

    转自 http://blog.sina.com.cn/s/blog_6d5560f00102vax6.html Quartus II 中的文本编辑软件不好用,比较习惯与UE(Uedit32/ultra ...

  5. C# webApi 与 AngularJs 实现增删改Demo 讲解(一)

    公司在使用webAPI+AngularJs+SlcikGrid进行产品开发,自己也是初学Angular,就做了一个Demo,实现增删改功能,希望可以帮助大家. 界面如同所示:  数据库一张单表很简单, ...

  6. linux /usr/bin/ld: cannot find -lxxx

    在linux环境编译应用程式或lib的source code时出现如下错误:/usr/bin/ld: cannot find -lxxx 这些讯息会随着编译不同类型的source code 而有不同的 ...

  7. Awesome Machine Learning

    https://github.com/josephmisiti/awesome-machine-learning 包含了很多的machine-learning开源的资源,包括各种语言的machin l ...

  8. VS2015 建立C++ dll库文件

    最近在写一个图片处理,正好用到C++封装DLL给C#调用,一下是总结:   建立一个C++的Win32DLL,这里要注意选择"Export symbols"导出符号.点击完成. 如 ...

  9. 抓包工具Charles,anyproxy,mitmproxy等

    Charles:图形化界面,看着比较方便友好,也可以抓取https,不过电脑和手机都要下载证书,主要我的电脑上不能添加一添加就卡死 所以,抓取https的话,就用mitmproxy比较简单 1.安装C ...

  10. DOM、JDOM、DOM4J的区别(转载)

    DOM.JDOM.DOM4J的区别 分类: XML2012-06-11 20:47 5576人阅读 评论(6) 收藏 举报 文档xmlcollectionsjavaapi工作 dom是解析xml的底层 ...