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 ...
随机推荐
- .Net如何在后台设置日期格式,并显示在前台页面上
其实方法比较老咯,有比这个简单的朋友请留言哈,我的思路是先将数据库中的日期格式读出来,在后台转化成DatetTime类型,然后在使用DateTime的内部方法设置日期格式,代码如下: DateTime ...
- PHP安全编程:不要让不相关的人看到报错信息
没有不会犯错的开发者,PHP的错误报告功 能可以协助你确认和定位这些错误,可以提供的这些错误的详细描述,但如果被恶意攻击者看到,这就不妙了.不能让大众看到报错信息,这一点很重要.做到这一 点很容易,只 ...
- mongodb配置文件.conf
启动方式 ./bin/mongod -f MongoDB.conf 会看到 about to fork child process, waiting until server is ready for ...
- spring集成activeMQ
1.安装activehttp://activemq.apache.org/activemq-5140-release.html2.运行D:\apache-activemq-5.14.0\bin\win ...
- iOS高效调试
写代码难免出现bug. 储备些调试技能绝对能够提高你的工作效率,让bug无所遁形.下面就和大家分享一些我在工作中常用的iOS调试小技能. 1. 打印 最简单,基础的调试方法就是打印日志了.贴出两段封装 ...
- Eclipse 安装SVN
地址:http://wenku.baidu.com/link?url=ntQy2-1CjlNyUpO0-4uhROrc9jCo12Yifh7MkPULmY_dCybl6SEH99SxYxEbZQEiW ...
- React基础语法学习
React主要有如下3个特点: 作为UI(Just the UI) 虚拟DOM(Virtual DOM):这是亮点 是React最重要的一个特性 放进内存 最小更新的视图,差异部分更新 diff算法 ...
- Java -- 子类使用super调用父类的方法A,A 调用了方法B,子类也override方法B,那么super.A()最终调用到了子类的B方法
public class SuperClass{ public void printA(){ System.out.print("SuperClass-printA"); prin ...
- MySQL 主从同步
http://blog.csdn.net/z69183787/article/details/53897894
- .net学习之委托和事件
1.什么是委托通俗的说:委托就是一个能够存储符合某种格式(方法签名)的方法的指针的容器上传图片: 2.委托语法准备一个方法:string Hello(string userName){} string ...