SZU-A22
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的更多相关文章
- P3436 [POI2006]PRO-Professor Szu
P3436 [POI2006]PRO-Professor Szu 题目描述 n个别墅以及一个主建筑楼,从每个别墅都有很多种不同方式走到主建筑楼,其中不同的定义是(每条边可以走多次,如果走边的顺序有一条 ...
- SZU:B47 Big Integer II
Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Normal Descrip ...
- SZU:D89 The Settlers of Catan
Judge Info Memory Limit: 65536KB Case Time Limit: 3000MS Time Limit: 3000MS Judger: Number Only Judg ...
- SZU:B47 Big Integer I
Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Normal Descrip ...
- SZU:G32 Mass fraction
Judge Info Memory Limit: 32768KB Case Time Limit: 5000MS Time Limit: 5000MS Judger: Float Numbers (1 ...
- SZU:J38 Number Base Conversion
Judge Info Memory Limit: 32768KB Case Time Limit: 1000MS Time Limit: 1000MS Judger: Number Only Judg ...
- SZU:B54 Dual Palindromes
Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Number Only Ju ...
- SZU:A66 Plastic Digits
Description There is a company that makes plastic digits which are primarily put on the front door o ...
- SZU:G34 Love code
Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Normal Descrip ...
- SZU:A25 Favorite Number
Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Number Only Ju ...
随机推荐
- unity3d 加密资源并缓存加载
原地址:http://www.cnblogs.com/88999660/archive/2013/04/10/3011912.html 首先要鄙视下unity3d的文档编写人员极度不负责任,到发帖为止 ...
- [LA4108]SKYLINE
[LA4108]SKYLINE 试题描述 The skyline of Singapore as viewed from the Marina Promenade (shown on the left ...
- ubuntu 快速安装jre
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java7-i ...
- ZeroMQ(java)之负载均衡
我们在实际的应用中最常遇到的场景如下: A向B发送请求,B向A返回结果.... 但是这种场景就会很容易变成这个样子: 很多A向B发送请求,所以B要不断的处理这些请求,所以就会很容易想到对B进行扩展,由 ...
- 将linux用在开发环境中
我是如何将linux用在开发环境中的 1.为什么不直接安装Linux在主机 一直想深入学习一下linux的使用,于是将家里的笔记本装了linux系统,但是要将自己的系统打造一个适合开发的环境确实是一件 ...
- poj1182(食物链)续
意 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C吃A. 现有N个动物,以1-N编号.每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种. 有人用 ...
- django动态表格总结
应用场景: A与B之间存在一对多关系. CBV实现方案: CreateView/UpdateView + inlineformset + jquery 具体: view方面:重写post/get方法, ...
- 用Matplotlib绘制二维图像
唠叨几句: 近期在做数据分析,需要对数据做可视化处理,也就是画图,一般是用Matlib来做,但Matlib安装文件太大,不太想直接用它,据说其代码运行效率也很低,在网上看到可以先用Java做数据处理, ...
- TFS增加dataserver
通过之前的努力,已经搭建好了一套基本的tfs环境,包括一台nameserver和一台dataserver以及独立的nginx-tfs,而在实际应用中的分布式文件系统,只有一台dataserver明显是 ...
- 【持续集成】[Jenkins]Job中如何传递自定义变量
[Jenkins]Job中如何传递自定义变量 来自dweiwei 2015-06-27 18:37:19| 分类: 自动化测试 |举报 |字号大中小 订阅 用微信 “扫一扫” 将文章分享到朋友 ...