时间限制: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的更多相关文章

  1. HDU 5640 King's Cake

    King's Cake Problem Description It is the king's birthday before the military parade . The ministers ...

  2. 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 ...

  3. hdu 5640 King's Cake(模拟)

    Problem Description   It is the king's birthday before the military parade . The ministers prepared ...

  4. BestCoder Round #75 1001 - King's Cake

    Problem Description It is the king's birthday before the military parade . The ministers prepared a ...

  5. BestCoder Round #75 King&#39;s Cake 模拟&amp;&amp;优化 || gcd

    King's Cake Accepts: 967 Submissions: 1572 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6553 ...

  6. 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 ...

  7. HDU 5640

    King's Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  8. hdu-5640 King's Cake (水题)

    题目链接 King's Cake Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others ...

  9. 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 ...

随机推荐

  1. 【leetcode】Single Number II (medium) ★ 自己没做出来....

    Given an array of integers, every element appears three times except for one. Find that single one. ...

  2. 【HOG】

    http://blog.csdn.net/masibuaa/article/details/12917961 把这份资料大概看完了 大概了解Hog了

  3. 【sqlite】python备份数据库

    备份整个数据库的方法: # coding=utf-8 import sqlite3 def testBakSqlite(): conn = sqlite3.connect("sqlite_d ...

  4. 导出 SQL SERVER 表中数据为脚本

    ALTER PROCEDURE [dbo].[Usp_OutputData] @tablename sysname, @outputIdentitycolumn int AS declare @col ...

  5. js中我的注释规范

    模块功能描述说明: /** * ------------------------------------------------------------------ * 模块描述说明 * ------ ...

  6. Redis内存管理(一)

    Redis数据库的内存管理函数有关的文件为:zmalloc.h和zmalloc.c. Redis作者在编写内存管理模块时考虑到了查看系统内是否安装了TCMalloc或者Jemalloc模块,这两个是已 ...

  7. 使用detours实现劫持

    第一步:下载detours3.0,安装detours 第二步:构建库文件,nmake编译 第三步:包含库文件和头文件 #include "detours.h" //载入头文件 #p ...

  8. 微信支付 - V3支付问题

    参考资料:http://www.2cto.com/weixin/201506/407690.html   1.微信公众号支付出错: 当前页面的URL未注册: get_brand_wcpay_reque ...

  9. poj 2262【素数表的应用---判断素数】【哈希】

    Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 35214   Accepted: ...

  10. SQL高级查询之一

    一,子查询 SELECT e.emp_id, e.fname, e.lname FROM (SELECT emp_id, fname, lname, start_date, title FROM em ...