Problem(A22):Party

Judge Info
Memory Limit: 32768KB
Case Time Limit: 10000MS
Time Limit: 10000MS
Judger: Number Only Judger

Description
Frog Frank is going to have a party, he needs a large empty rectangular place. He ranted a large rectangular place in the forest, unfortunately the place is not empty, there are some trees in it. For solving the problem, he makes a map of the rectangular place with m × n grid, he paint the grid to black if there are some trees in it. Now, all he needs to do is find the largest rectangular place in the map contains no black grid.

Task
Frank is asking your help to find out, the area(the number of grids) of the largest rectangular place without black grid.

Input
The first line of input contains , the number of test cases. For each test case, the first contains two integer number m and n , denotes the size of the map. In the next m lines, each line contains a string with n ’0’,’1’ characters, ’0’ denotes the empty grid, ’1’ denotes the black grid.

Output
For each test case, print the area(the number of grids) of the largest rectangular place in a line.

Sample Input
2
3 3
111
100
111
5 5
10101
00100
00000
00000
00001
Sample Output
2
12

分析:n,m最大值为10,总时间竟然给了10s!本来还担心时间问题,一看这规模完全不用了.
注:我把本题中01地位互换了一下.
设f[i][j]为第i行第j列左边有多少个连续的1(包括第j列)
对于某个f[i][j]如果f[i-1][j]>f[i][j],那不妨扩充一层,向下类似,直到f[x][j]>f[i][j]为止.这样我们就得到了一个由[i,j]张成的矩形.通过比较这n*m个矩形就可以得出最大面积了.

#include<stdio.h>
#include<string.h>
char s[][];
int f[][];
int main()
{
int T;
scanf("%d",&T);
int n,m;
while (T--)
{
scanf("%d%d",&n,&m);
memset(f,,sizeof(f));
int i,j,k;
for (i=;i<=n;i++) scanf("%s",s[i]);
for (i=;i<=n;i++)
for (j=;j<=m;j++)
if (s[i][j-]=='') f[i][j]=;
else f[i][j]=;
for (i=;i<=n;i++)
for (j=;j<=m;j++)
if (f[i][j]==) f[i][j]=f[i][j-]+;
int Max=0,l,r;
for (i=;i<=n;i++)
for (j=;j<=m;j++)
{
for (k=i;k>=;k--)
if (f[k-][j]<f[i][j])
{
l=k;
break;
}
for (k=i;k<=n;k++)
if (f[k+][j]<f[i][j])
{
r=k;
break;
}
if (f[i][j]*(r-l+)>Max) Max=f[i][j]*(r-l+);
}
printf("%d\n",Max);
}
return ;
}

SZU-A22的更多相关文章

  1. P3436 [POI2006]PRO-Professor Szu

    P3436 [POI2006]PRO-Professor Szu 题目描述 n个别墅以及一个主建筑楼,从每个别墅都有很多种不同方式走到主建筑楼,其中不同的定义是(每条边可以走多次,如果走边的顺序有一条 ...

  2. SZU:B47 Big Integer II

    Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Normal Descrip ...

  3. SZU:D89 The Settlers of Catan

    Judge Info Memory Limit: 65536KB Case Time Limit: 3000MS Time Limit: 3000MS Judger: Number Only Judg ...

  4. SZU:B47 Big Integer I

    Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Normal Descrip ...

  5. SZU:G32 Mass fraction

    Judge Info Memory Limit: 32768KB Case Time Limit: 5000MS Time Limit: 5000MS Judger: Float Numbers (1 ...

  6. SZU:J38 Number Base Conversion

    Judge Info Memory Limit: 32768KB Case Time Limit: 1000MS Time Limit: 1000MS Judger: Number Only Judg ...

  7. SZU:B54 Dual Palindromes

    Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Number Only Ju ...

  8. SZU:A66 Plastic Digits

    Description There is a company that makes plastic digits which are primarily put on the front door o ...

  9. SZU:G34 Love code

    Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Normal Descrip ...

  10. SZU:A25 Favorite Number

    Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Number Only Ju ...

随机推荐

  1. iphone数据存储之-- Core Data的使用(一)

    http://www.cnblogs.com/xiaodao/archive/2012/10/08/2715477.html 一.概念 1.Core Data 是数据持久化存储的最佳方式 2.数据最终 ...

  2. uc_client是如何与UCenter进行通信的

    以用户登录为例介绍,其它注销,改密码,消息,头像,好友均类同. 从用户xxx在某一应用程序的login.php,输入用户名,密码讲起.先用uc_user_login函数到uc_server验证此用户和 ...

  3. CSS3.0盒模型display:-webkit-box;的使用

    box-flex是css3新添加的盒子模型属性,它的出现可以解决我们通过N多结构.css实现的布局方式.经典   的一个布局应用就是布局的垂直等高.水平均分.按比例划分. 目前box-flex属性还没 ...

  4. 【Redis】Redis分布式集群几点说道

    Redis数据量日益增大,使用的公司越来越多,不仅用于做缓存,同时趋向于存储这一块,这样必促使集群的发展,各个公司也在收集适合自己的集群方案,目前行业用的比较多的是下面几种集群架构,大部分都是采用分片 ...

  5. 【OpenStack】OpenStack系列1之Python虚拟环境搭建

    安装virtualenv相关软件包 安装:yum install python-virtualenv* -y 简介,安装包主要包括, python-virtualenv:virtualenv用于创建独 ...

  6. 【云计算】开源的Docker Registry WebUI

    kwk/docker-registry-frontend   Code       Issues         9       Pull requests       6       Wiki   ...

  7. SpringMVC请求处理流程

    从web.xml中 servlet的配置开始, 根据servlet拦截的url-parttern,来进行请求转发   Spring MVC工作流程图   图一   图二    Spring工作流程描述 ...

  8. 【leetcode】Binary Search Tree Iterator

    Binary Search Tree Iterator Implement an iterator over a binary search tree (BST). Your iterator wil ...

  9. python动态获取对象的属性和方法

    http://blog.csdn.net/kenkywu/article/details/6822220首先通过一个例子来看一下本文中可能用到的对象和相关概念.01     #coding: UTF- ...

  10. 如何用BMFont制作图片字

    1: 运行程序,单击鼠标左键点亮相应位置的字母,比如:0.1.2./ 等2: 选择 Edit->Open Image Manager.弹出一个“Image Manager" 对话框3: ...