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 ...
随机推荐
- 【linux】学习1
郁闷啊 好多东西要学 下面大概就是鸟哥那本书的第五章内容吧 linux命令: Ctrl + Alt + F1 ~ F6 : 切换终端 ls -al ~ :显示主文件夹下的所有隐藏文件 date: ...
- [Android Pro] http请求中传输base64出现加号变空格的解决办法
reference to : http://blog.csdn.net/jsjwbxzy/article/details/45970231 try { des = URLEncoder.encode( ...
- [网络流24题] 太空飞行计划(cogs 727)
[问题描述] W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合E={E1,E2,-,Em},和进行这些实验需要使用的全部仪 ...
- chaper3_exerise_UVa455_周期串
#include<iostream> #include<cstring> #include<stdio.h> using namespace std; ; int ...
- python基础——高阶函数
python基础——高阶函数 高阶函数英文叫Higher-order function.什么是高阶函数?我们以实际代码为例子,一步一步深入概念. 变量可以指向函数 以Python内置的求绝对值的函数a ...
- 5.1 stack,queue以及priority_queue
*:stack 使用要包含头文件stack,栈是一种先进后出的元素序列,删除和访问只能对栈顶的元素(最后一个添加的元素)进行,并且添加元素只能添加到栈顶.栈内的元素不能访问,要想访问先要删除其上方的所 ...
- EmguCV学习 与opencv的区别和联系
openCV是因特尔的一个开源的视觉库,里面几乎包含了所有的图像处理的经典算法,并且采用C和少量的C++编写,运行效率很高,对于做图像处理这方面工作的,认识opencv是必须的工作.不过opencv有 ...
- Linq学习笔记---Linq to Xml操作
LINQ to XML的成员, 属性列表: 属性 说明 Document 获取此 XObject 的 XDocument EmptySequence 获取空的元素集合 FirstAttribut ...
- C#的索引器
using System; using System.Collections; using System.Collections.Generic; using System.IO; namespace ...
- Redis笔记(六)Redis的消息通知
Redis的消息通知可以使用List类型的LPUSH和RPOP(左进右出),当然更方便的是直接使用Redis的Pub/Sub(发布/订阅)模式. >>使用List实现队列 使用列表类型的L ...