时间限制:1000MS  内存限制:65535K
提交次数:0 通过次数:0

题型: 编程题   语言: G++;GCC

Description

  1. 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)

输入格式

  1. The first line contains the one integer number M (1<= M<=1,000). Then M lines are following. Each line contains M
  2. charactors which “.” means cloth and H means hole.

输出格式

  1. The only line of the output contains area of the biggest square cloth mentioned above.

输入样例

  1. 5
  2. H...H
  3. .....
  4. .....
  5. .HHH.
  6. .....

输出样例

  1. 9

作者

admin

思路:比较经典的模型了,大白上有几乎一样的原题

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. using namespace std;
  5. const int N = ;
  6. char Map[N][N];
  7. int Up[N][N], Left[N][N], Right[N][N];
  8. int n;
  9. void getL() {
  10. for(int i = ; i <= n; ++i) {
  11. int lo = ;
  12. for(int j = ; j <= n; ++j) {
  13. if(Map[i][j] == '.') {
  14. Up[i][j] = Up[i - ][j] + ;
  15. Left[i][j] = max(Left[i - ][j], lo + );
  16. }else {
  17. Up[i][j] = Left[i][j] = ;
  18. lo = j;
  19. }
  20. }
  21. }
  22. }
  23. int ans = ;
  24. void getR() {
  25. for(int i = ; i <= n; ++i) {
  26. int ro = n + ;
  27. for(int j = n; j >= ; --j) {
  28. if(Map[i][j] == '.') {
  29. Right[i][j] = min(Right[i - ][j], ro - );
  30. }else {
  31. Right[i][j] = n;
  32. ro = j;
  33. }
  34. ans = max(ans, min(Up[i][j], Right[i][j] - Left[i][j] + ));
  35. }
  36. }
  37. }
  38. void show(int a[][N]) {
  39. for(int i = ; i <= n; ++i) {
  40. for(int j = ; j <= n; ++j) printf("%d ", a[i][j]);
  41. puts("");
  42. }
  43. }
  44. int main() {
  45. while(~scanf("%d", &n)) {
  46. for(int i = ; i <= n; ++i) scanf("%s", Map[i] + );
  47. for(int i = ; i <= n; ++i) Up[][i] = ;
  48. for(int i = ; i <= n; ++i) Left[][i] = ;
  49. for(int i = ; i <= n; ++i) Right[][i] = n;
  50. getL();
  51. getR();
  52. printf("%d\n", ans * ans);
  53. }
  54. return ;
  55. }
  56. /*
  57. 5
  58. HH.HH
  59. .....
  60. .....
  61. H...H
  62. HHHHH
  63. */

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. 【QT】C++ GUI Qt4 学习笔记2

    Go To Cell 利用QT Desinger做好界面后加入的代码有 gotocelldialog.h #ifndef GOTOCELLDIALOG_H #define GOTOCELLDIALOG ...

  2. [jquery]判断页面滚动到顶部和底部(适用于手机web加载)

    //判断页面滚动到顶部和底部 $(window).scroll(function(){ var doc_height = $(document).height(); var scroll_top = ...

  3. Rsync+lsync实现触发式实时同步

    使用rsync+lsync实现触发式实时同步 服务器信息 centos6.5 主:192.168.5.4 搭建lsync 从:192.168.5.3 搭建rsync 1.1 从服务器设置 # yum ...

  4. osg四元数设置roll pitch heading角度

    roll绕Y轴旋转 pitch绕X轴旋转 heading绕Z轴旋转 单位是弧度,可以使用osg::inDegrees(45)将45角度转换为弧度 定义一个四元数 osg::Quat q( roll,o ...

  5. Java RSA 密钥生成工具

    MAC openssl: RSA加解密 第一条命令是生成密钥长度为1024的密钥: 第二条命令是从中生成公钥: 第三条命令是使用pkcs8编码密钥为私钥 http://blog.csdn.net/ch ...

  6. 使用DateUtils和DateFormatUtils处理时间日期转换与SimpleDateFormat的区别

    在Apache Commons项目的Lang里面,有两个类:DateUtils和DateFormatUtils,专门用于处理时间日期转换.它们在 org.apache.commons.lang.tim ...

  7. Python下安装MySQLdb

    前提是你已经安装过mysql 1.从https://pypi.python.org/pypi/MySQL-python/下载MySQL-python,然后用rz命令上传到相关目录 2.用tar -zx ...

  8. ***PHP中error_reporting()用法详解(含codeigniter框架中屏蔽错误提示的解决方案)

    php中我们对错误的处理会常用到error_reporting函数了,大家可以看到最多的是error_reporting(E_ALL ^ E_NOTICE)了,这个到底什么意思呢,下面我来来看看. e ...

  9. Pyqt 时时CPU使用情况

    借鉴代码来自:https://github.com/hgoldfish/quickpanel 实现代码: # -*- coding:utf-8 -*- from __future__ import p ...

  10. Jquery自定义图片上传插件

    1 概述 编写后台网站程序大多数用到文件上传,可是传统的文件上传控件不是外观不够优雅,就是性能不太好看,翻阅众多文件上传控件的文章,发现可以这样去定义一个文件上传控件,实现的文件上传的效果图如下: 2 ...