博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVALive - 3029 City Game
阅读量:6567 次
发布时间:2019-06-24

本文共 3228 字,大约阅读时间需要 10 分钟。

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 l

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.

 

题解:

  这个题目有点难想,我只想到一个n^3方的暴力。

  对于一个点,我们维护三个信息,1.他向上最大能延伸到哪里(up[i][j]),把他向上延伸的网格看成一条线。2.他向带着这根线最多可以延伸到哪里lt[i][j]。3.他带着这根线向右最多可以延伸到哪里rt[i][j]。

  然后我们枚举格点,最大的up[i][j]*(right[i][j]-left[i][j]+1)就是答案,因为up[i][j]*(right[i][j]-left[i][j]+1)就相当于是在i行以上的包括(i,j)的最大矩形的面积,就可以求出答案了。

 

代码:

#include 
#include
#include
#include
#include
#include
#define MAXN 1200using namespace std;int lt[MAXN][MAXN],rt[MAXN][MAXN],up[MAXN][MAXN],mp[MAXN][MAXN];int n,m;void cl(){ memset(lt,0,sizeof(lt)); memset(rt,0,sizeof(rt)); memset(up,0,sizeof(up)); memset(mp,0,sizeof(mp));}void work(){ cl(); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ char ch=getchar(); while(ch!='R'&&ch!='F') ch=getchar(); mp[i][j]=(ch=='R'); } } int ans=0; for(int i=1;i<=n;i++){ int hh=0; for(int j=1;j<=m;j++){ if(mp[i][j]) up[i][j]=lt[i][j]=0,hh=j; else{ if(i==1) up[i][j]=1,lt[i][j]=hh+1; else up[i][j]=up[i-1][j]+1,lt[i][j]=max(hh+1,lt[i-1][j]); } } hh=m+1; for(int j=m;j>=1;j--){ if(mp[i][j]) rt[i][j]=m+1,hh=j; else{ if(i==1) rt[i][j]=hh-1; else rt[i][j]=min(hh-1,rt[i-1][j]); } ans=max(ans,(rt[i][j]-lt[i][j]+1)*up[i][j]); } } printf("%d\n",ans*3);}int main(){ int t;cin>>t; while(t--){ work(); } return 0;}

 

转载于:https://www.cnblogs.com/renjianshige/p/7649377.html

你可能感兴趣的文章
ZBar之ZBarReaderViewController
查看>>
Nuget~管理自己的包包~丢了的包包快速恢复
查看>>
$.extend({},defaults, options) --(初体验三)
查看>>
jQuery hover() 方法
查看>>
android 一步一步教你集成tinker(热修复)
查看>>
到底有多少内存
查看>>
centos7.3 安装ovirt-engine4.0 版本
查看>>
Jenkins+git+tomcat 自动化持续部署
查看>>
项目log日志打印
查看>>
Openstack的环境的Mitaka部署环境服务,实例(1)
查看>>
文档的压缩与打包
查看>>
python3 在不同操作系统安装第三方库方法
查看>>
redhat5.8+mfs(提供软件包文档)
查看>>
python编写登录接口
查看>>
MySQL高可用方案之多级复制
查看>>
OVS 中的各种网络设备 - 每天5分钟玩转 OpenStack(128)
查看>>
Python火车票代码
查看>>
Android开发者指南(7) —— App Install Location
查看>>
Trafficserver Cluster模式
查看>>
亚马逊推出 Blox,用于 EC2 容器服务的开源工具集合
查看>>