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 ...
随机推荐
- [Effective JavaScript 笔记]第43条:使用Object的直接实例构造轻量级的字典
js对象的核心是一个字符串属性名与属性值的映射表.使用对象实现字典易如反掌,字典是可变长的字符串与值的映射集合. for...in js提供了枚举一个对象属性名的利器--for...in循环. var ...
- scrollview里面多张图片,每张都能放大缩小
http://blog.sina.com.cn/s/blog_5d68044001018s1n.html scrollview里面多张图片,每张都能放大缩小 - (void)viewDidLoad{ ...
- OpenCV入门(一)
参考:http://blog.csdn.net/poem_qianmo/article/details/20537737 这位同学挺牛的,才研一就出书了,实在是让人汗颜啊,不说了,多学习. 这一篇主要 ...
- php页面打开响应时间
$start_time = array_sum(explode(' ',microtime())); //your code here $end_time = array_sum(explode( ...
- ubuntu12.04 Daemon的简单实现
使用命令 start-stop-daemon 官方文档:http://manpages.ubuntu.com/manpages/lucid/en/man8/start-stop-daemon.8.ht ...
- 用php实现百度网盘图片直链的代码分享
第一种代码:代码量较少通过正则表达式获取百度网盘的文件真实地址,来实现直链的效果 将下面的代码保存为downbd.php 复制代码代码如下: <?php $canshu=$_SERVER[&qu ...
- (部署新java程序,程序报错,需copy的一个包)——java使用siger 获取服务器硬件信息
mcat-siger.sh 查看是否安装siger rsync -aPuv /usr/lib64/libsigar-amd64-linux.so $i:/usr/lib64/ java使用siger ...
- SSM框架Web程序的流程(Spring SpringMVC Mybatis)
SSM框架的Web程序主要用到了三个技术: Spring:用到了注解和自动装配,就是Spring的两个精髓IOC(反向控制)和 AOP(面向切面编程). SpringMVC:用到了MVC模型,将逻辑代 ...
- sharepoint获取域名和当前登录的应为名字
string a = SPContext.Current.Web.CurrentUser.ToString(); int length = a.IndexOf("w|", 0) ...
- iOS中的NSTimer 和 Android 中的Timer
首先看iOS的, Scheduling Timers in Run Loops A timer object can be registered in only one run loop at a t ...