Scau 10327 Biggest Square
时间限制:1000MS 内存限制:65535K
提交次数:0 通过次数:0
题型: 编程题 语言: G++;GCC
Description
You are given a M*M cloth with some holes on it. Your task is to find a biggest square cloth from it. The following is an example(M=5)

输入格式
The first line contains the one integer number M (1<= M<=1,000). Then M lines are following. Each line contains M
charactors which “.” means cloth and “H” means hole.
输出格式
The only line of the output contains area of the biggest square cloth mentioned above.
输入样例
5
H...H
.....
.....
.HHH.
.....
输出样例
9
作者
admin
思路:比较经典的模型了,大白上有几乎一样的原题
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = ;
char Map[N][N];
int Up[N][N], Left[N][N], Right[N][N];
int n;
void getL() {
for(int i = ; i <= n; ++i) {
int lo = ;
for(int j = ; j <= n; ++j) {
if(Map[i][j] == '.') {
Up[i][j] = Up[i - ][j] + ;
Left[i][j] = max(Left[i - ][j], lo + );
}else {
Up[i][j] = Left[i][j] = ;
lo = j;
}
}
}
}
int ans = ;
void getR() {
for(int i = ; i <= n; ++i) {
int ro = n + ;
for(int j = n; j >= ; --j) {
if(Map[i][j] == '.') {
Right[i][j] = min(Right[i - ][j], ro - );
}else {
Right[i][j] = n;
ro = j;
}
ans = max(ans, min(Up[i][j], Right[i][j] - Left[i][j] + ));
}
}
}
void show(int a[][N]) {
for(int i = ; i <= n; ++i) {
for(int j = ; j <= n; ++j) printf("%d ", a[i][j]);
puts("");
}
}
int main() {
while(~scanf("%d", &n)) {
for(int i = ; i <= n; ++i) scanf("%s", Map[i] + );
for(int i = ; i <= n; ++i) Up[][i] = ;
for(int i = ; i <= n; ++i) Left[][i] = ;
for(int i = ; i <= n; ++i) Right[][i] = n;
getL();
getR();
printf("%d\n", ans * ans);
}
return ;
}
/*
5
HH.HH
.....
.....
H...H
HHHHH
*/
Scau 10327 Biggest Square的更多相关文章
- HDU 5640 King's Cake
King's Cake Problem Description It is the king's birthday before the military parade . The ministers ...
- hdu 5640 King's Cake(BestCoder Round #75)
King's Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu 5640 King's Cake(模拟)
Problem Description It is the king's birthday before the military parade . The ministers prepared ...
- BestCoder Round #75 1001 - King's Cake
Problem Description It is the king's birthday before the military parade . The ministers prepared a ...
- BestCoder Round #75 King's Cake 模拟&&优化 || gcd
King's Cake Accepts: 967 Submissions: 1572 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6553 ...
- HDU 5640 King's Cake GCD
King's Cake 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5640 Description It is the king's birthd ...
- HDU 5640
King's Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu-5640 King's Cake (水题)
题目链接 King's Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- Codeforces Round #356 (Div. 1) C. Bear and Square Grid
C. Bear and Square Grid time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- jsp通过s:hidden传值给后台,后台数据出现了若干逗号问题
<s:iterator value="rpActionVO.page.result" id="list" status="st"> ...
- powerdesigner新建模型教程
1.现在开始使用PowerDesigner创建数据库,首先运行程序,进入主界面:
- ZendStudio如何汉化
点击工具栏的help,看图 点击 Install New Sofaware... 看图 然后.... 在地址(12.0的版本):http://download.eclipse.org/techno ...
- MongoDB C API
一.编译mongodb c driver: 编译完成之后在c:\mongo-c-driver目录下有bin.include.lib三个文件夹,分别包含所需的dll..h文件.lib. 在自己的项目中引 ...
- NYOJ题目766回文数
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsgAAAHaCAIAAACSPygsAAAgAElEQVR4nO3dO3LqSheG4X8S5AyEWB ...
- 简单的mysql封装类
class mysql{ private $host; private $user; private $pwd; private $dbname; private $charset; private ...
- OpenCv,EmguCv及.net之间的互动(The Interaction of OpenCv, EmguCv AND .net)
http://www.cnblogs.com/xrwang/archive/2010/01/26/TheInteractionOfOpenCv-EmguCvANDDotNet.html 前言 在.ne ...
- jq 轮播图
<style> #focus{width:500px;height:200px;overflow:hidden;/*用一个div把图片包含设置超出范围隐藏*/} </style> ...
- Asp.Net - 7.AJAX
AJAX简介 没有AJAX会怎么样?普通的ASP.Net每次执行服务端方法的时候都要刷新当前页面,比如实现显示服务器的时间.每次都要刷新面的坏处:页面刷新打断用户操作.速度慢.增加服务器的流量压力.如 ...
- Linux snmp
http://www.cnblogs.com/amberly/p/4364072.html http://blog.csdn.net/awenluck/article/details/50220221