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 ...
随机推荐
- 【QT】C++ GUI Qt4 学习笔记2
Go To Cell 利用QT Desinger做好界面后加入的代码有 gotocelldialog.h #ifndef GOTOCELLDIALOG_H #define GOTOCELLDIALOG ...
- [jquery]判断页面滚动到顶部和底部(适用于手机web加载)
//判断页面滚动到顶部和底部 $(window).scroll(function(){ var doc_height = $(document).height(); var scroll_top = ...
- Rsync+lsync实现触发式实时同步
使用rsync+lsync实现触发式实时同步 服务器信息 centos6.5 主:192.168.5.4 搭建lsync 从:192.168.5.3 搭建rsync 1.1 从服务器设置 # yum ...
- osg四元数设置roll pitch heading角度
roll绕Y轴旋转 pitch绕X轴旋转 heading绕Z轴旋转 单位是弧度,可以使用osg::inDegrees(45)将45角度转换为弧度 定义一个四元数 osg::Quat q( roll,o ...
- Java RSA 密钥生成工具
MAC openssl: RSA加解密 第一条命令是生成密钥长度为1024的密钥: 第二条命令是从中生成公钥: 第三条命令是使用pkcs8编码密钥为私钥 http://blog.csdn.net/ch ...
- 使用DateUtils和DateFormatUtils处理时间日期转换与SimpleDateFormat的区别
在Apache Commons项目的Lang里面,有两个类:DateUtils和DateFormatUtils,专门用于处理时间日期转换.它们在 org.apache.commons.lang.tim ...
- Python下安装MySQLdb
前提是你已经安装过mysql 1.从https://pypi.python.org/pypi/MySQL-python/下载MySQL-python,然后用rz命令上传到相关目录 2.用tar -zx ...
- ***PHP中error_reporting()用法详解(含codeigniter框架中屏蔽错误提示的解决方案)
php中我们对错误的处理会常用到error_reporting函数了,大家可以看到最多的是error_reporting(E_ALL ^ E_NOTICE)了,这个到底什么意思呢,下面我来来看看. e ...
- Pyqt 时时CPU使用情况
借鉴代码来自:https://github.com/hgoldfish/quickpanel 实现代码: # -*- coding:utf-8 -*- from __future__ import p ...
- Jquery自定义图片上传插件
1 概述 编写后台网站程序大多数用到文件上传,可是传统的文件上传控件不是外观不够优雅,就是性能不太好看,翻阅众多文件上传控件的文章,发现可以这样去定义一个文件上传控件,实现的文件上传的效果图如下: 2 ...