la----3695 City Game(最大子矩阵)
Bob is a strategy game programming specialist. In his new city building game the gaming environment is as follows: a city is built up by areas, in which there are streets, trees, factories and buildings. There is still some space in the area that is unoccupied. The strategic task of his game is to win as much rent money from these free spaces. To win rent money you must erect buildings, that can only be rectangular, as long and wide as you can. Bob is trying to find a way to build the biggest possible building in each area. But he comes across some problems � he is not allowed to destroy already existing buildings, trees, factories and streets in the area he is building in.
Each area has its width and length. The area is divided into a grid of equal square units. The rent paid for each unit on which you're building stands is 3$.
Your task is to help Bob solve this problem. The whole city is divided into K areas. Each one of the areas is rectangular and has a different grid size with its own length M and width N. The existing occupied units are marked with the symbol R. The unoccupied units are marked with the symbol F.
Input
The first line of the input file contains an integer K � determining the number of datasets. Next lines contain the area descriptions. One description is defined in the following way: The first line contains two integers-area length M<=1000 and width N<=1000, separated by a blank space. The next M lines contain N symbols that mark the reserved or free grid units, separated by a blank space. The symbols used are:
R � reserved unit
F � free unit
In the end of each area description there is a separating line.
Output
For each data set in the input file print on a separate line, on the standard output, the integer that represents the profit obtained by erecting the largest building in the area encoded by the data set.
Sample Input
2
5 6
R F F F F F
F F F F F F
R R R F F F
F F F F F F
F F F F F F 5 5
R R R R R
R R R R R
R R R R R
R R R R R
R R R R R
Sample Output
45
0 代码 :
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 1000;
int sac[maxn][maxn];
int up[maxn][maxn],left[maxn][maxn],right[maxn][maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int m,n;
scanf("%d%d",&m,&n);
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
int ch=getchar();
while(ch!='F'&&ch!='R')
ch=getchar();
sac[i][j]=ch=='F'?0:1;
}
}
int ans=0;
for(int i=0;i<m;i++){
int lo=-1,ro=n;
for(int j=0;j<n;j++){
if(sac[i][j]==1)
{
up[i][j]=left[i][j]=0;
lo=j;
}
else
{
up[i][j]=i==0?1:up[i-1][j]+1;
left[i][j]=i==0?lo+1:max(left[i-1][j],lo+1);
}
}
for(int j=n-1;j>=0;j--)
{
if(sac[i][j]==1)
{
right[i][j]=n;
ro=j;
}
else
{
right[i][j]=i==0?ro-1:min(right[i-1][j],ro-1);
ans=max(ans,up[i][j]*(right[i][j]-left[i][j]+1));
}
}
}
printf("%d\n",ans*3);
}
return 0;
}
la----3695 City Game(最大子矩阵)的更多相关文章
- UVa LA 3029 City Game 状态拆分,最大子矩阵O(n2) 难度:2
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- City Game(最大子矩阵)
Bob is a strategy game programming specialist. In his new city building game the gaming environment ...
- LA 3029 City Game
LA 3029 求最大子矩阵问题,主要考虑枚举方法,直接枚举肯定是不行的,因为一个大矩阵的子矩阵个数是指数级的,因此应该考虑先进行枚举前的扫描工作. 使用left,right,up数组分别记录从i,j ...
- LA 3029 - City Game (简单扫描线)
题目链接 题意:给一个m*n的矩阵, 其中一些格子是空地(F), 其他是障碍(R).找一个全部由F 组成的面积最大的子矩阵, 输出其面积乘以3的结果. 思路:如果用枚举的方法,时间复杂度是O(m^2 ...
- UVaLive 3695 City Game (扫描线)
题意:给定m*n的矩阵,有的是空地有的是墙,找出一个面积最大的子矩阵. 析:如果暴力,一定会超时的.我们可以使用扫描线,up[i][j] 表示从(i, j)向上可以到达的最高高度,left[i][j] ...
- LA 3695 Distant Galaxy
给出n个点的坐标(坐标均为正数),求最多有多少点能同在一个矩形的边界上. 题解里是构造了这样的几个数组,图中表示的很明白了. 首先枚举两条水平线,然后left[i]表示竖线i左边位于水平线上的点,on ...
- UVa LA 3695 - Distant Galaxy 前缀和,状态拆分,动态规划 难度: 2
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- LA 3695 部分枚举
运用部分枚举的思想,很明显完全枚举点的思想是不可能的.改为枚举上下边界,当确定右边界j后,对左边界i,可以有点数为on[j]+on[i]+(leftu[j]-leftu[i])+leftd[j]-le ...
- SWT入门-常用组件的使用(转)
转自:http://www.cnblogs.com/kentyshang/archive/2007/08/16/858367.html swt的常用组件button ,text ,combo,list ...
随机推荐
- Phonegap项目中禁用WebViewBounce
UIWebView是iOS SDK中一个最常用的控件,在PhoneGap中,默认也是使用UIWebView作为默认视图显示我们的HTML应用的. 在使用PhoneGap的项目中,默认WebView ...
- Servlet与Tomcat
Web应用不仅局限于展示在服务器上的静态页面,更多的是根据用的请求动态的生成页面信息,还可以从数据库中提取数据,生成页面返回给用户. 第一种方法:遵循HTTP协议实现一个服务器端软件 第二种方法:利用 ...
- openstack 排错
1.查看日志 grep ERROR /var/log/keystone/keystone.log 2. # nova list ERROR:n/a (http 404) 检查环境变量是否正确.
- mysql概要(十三)备份和恢复
1.采用mysql 自带备份命令: 数据库恢复:
- [转载] Tmux 速成教程:技巧和调整
原文: http://blog.jobbole.com/87584/ 决定从 screen 转向 tmux 了, 非常喜欢 tmux 的窗格功能. 简介 有些开发者经常要使用终端控制台工作,导致最终打 ...
- 2014 Multi-University Training Contest 4
1006 hdu4902 #include <iostream> #include<stdio.h> #include<vector> #include<qu ...
- EAPOL 协议
EAPOL 协议 一.基本概念 EAPOL 的全称为 Extensible Authentication Protocol Over LAN,即 EAP Over Lan,也即基于局域网的扩展认证协议 ...
- Java后端开发
Java后端开发 名称 内容 基本框架 Spring.Mybatis Linux服务器 数据库优化 消息服务 rabbitMQ.activeMq rocketMq 缓存服务 memcached ...
- Android 项目中常用到的第三方组件
项目中常用到的第三方组件 1 社会化分享ShareSDK-Core-2.5.9.jarShareSDK-QQ-2.5.9.jarShareSDK-QZone-2.5.9.jarShareSDK-Sin ...
- SDL2.0的加载图片贴图
加载图片贴图,采用了SDL_Window.SDL_Renderer.SDL_Texture和SDL_Image库 实例: #include <stdio.h> #include <m ...