UVA - 1330 City Game
Input
The rst line of the input le contains an integer K | determining the number of datasets. Next lines
contain the area descriptions. One description is dened in the following way: The rst 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 le print on a separate line, on the standard output, the integer that
represents the prot 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
1.如何拆分最大矩形,遍历所有点的上左右边界,在遍历中求最大值
2.颠倒看数组都是一样的
#include <cstdio>
#include <algorithm>
#include <iostream> #define MAX 1000 using namespace std;
int A[MAX][MAX], up[MAX][MAX], l[MAX][MAX], r[MAX][MAX], m, n, T; int main() {
cin >> T;
while (T--) {
cin >> m >> n;
for (int i = , c; i < m; ++i) {
for (int j = ; j < n; ++j) {
do { c = getchar(); }
while (c != 'F' && c != 'R');
A[i][j] = c == 'F';
}
}
int ans = ;
for (int i = ; i < m; ++i) {
for (int j = , lo = ; j < n; ++j) {
if (!A[i][j]) {
up[i][j] = l[i][j] = ; //把l设到最左,方便上方的点求lo
lo = j + ;
} else {
up[i][j] = i == ? : up[i - ][j] + ;
l[i][j] = i == ? lo : max(l[i - ][j], lo);
}
} for (int j = n - , ro = n; j >= ; --j) {
if (!A[i][j]) {
r[i][j] = n, ro = j;
} else {
r[i][j] = i == ? ro : min(r[i - ][j], ro);
ans = max(ans, up[i][j] * (r[i][j] - l[i][j])); //在求右边界时同时求矩形面积最大值
}
}
}
cout << ans * << endl;
}
}
UVA - 1330 City Game的更多相关文章
- UVa 836 - Largest Submatrix
题目:给你一个n*n的01矩阵,求里面最大的1组成的矩形的米娜及. 分析:dp.单调队列.UVa 1330同题,仅仅是输入格式变了. 我们将问题分解成最大矩形.即求解以k行为底边的图形中的最大矩形.然 ...
- UVa LA 3029 City Game 状态拆分,最大子矩阵O(n2) 难度:2
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- UVA - 1025 A Spy in the Metro[DP DAG]
UVA - 1025 A Spy in the Metro Secret agent Maria was sent to Algorithms City to carry out an especia ...
- 10_放置街灯(Placing Lampposts,UVa 10859)
问题来源:刘汝佳<算法竞赛入门经典--训练指南> P70 例题30: 问题描述:有给你一个n个点m条边(m<n<=1000)的无向无环图,在尽量少的节点上放灯,使得所有边都被照 ...
- UVA 12950 : Even Obsession(最短路Dijkstra)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 590 二十一 Always on the run
Always on the run Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVA 1292 十二 Strategic game
Strategic game Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Sta ...
- UVA 11389(贪心问题)
UVA 11389 Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description II ...
- UVa 10048: Audiophobia
这道题要求我们求出图中的给定的两个节点(一个起点一个终点,但这是无向图)之间所有“路径中最大权值”的最小值,这无疑是动态规划. 我开始时想到根据起点和终点用动态规划直接求结果,但最终由于题中S过大,会 ...
随机推荐
- 《CSS权威指南(第三版)》---第七章 基本视觉格式化
主要知识记录: 1.给一个元素指定内容区宽度,如果设置了内边距,边框和外边距,这些因素都会影响CSS的width属性. 2.在水平格式化的7个属性中,width,margin-left,margin- ...
- js作用域总结
一.在ES5中,js 的作用域 js作用域,只有全局作用域与函数作用域,没有块级作用域. 1.全局作用域 var a = 10; function aaa() {alert(a) } function ...
- 破解 Navicat Premium 12
一.下载 若文件百度云链接失效,请发邮件给博主:1766211120@qq.com 1.安装文件下载 v12.0.11(x64)版本下载地址如下 链接:https://pan.baidu.com/s/ ...
- listen 72
Warmer Temps May Bollux Botanicals Global warming might seem like a botanical boon. After all, milde ...
- PC样式reset参考
/* html5doctor.com Reset Stylesheet */ * { padding:; margin:; list-style: none; } html, body, div, s ...
- OpenCV——旋转模糊
参考来源: 学习OpenCV:滤镜系列(5)--径向模糊:缩放&旋转 // define head function #ifndef PS_ALGORITHM_H_INCLUDED #defi ...
- 11g dataguard 类型、保护模式、服务
一. Dataguard中的备库分为物理备库和逻辑备库及快照备库 备库是主库的一致性拷贝,使用一个主库的备份可以创建多到30个备库,将其加入到dataguard环境中,创建成功后,dataguard通 ...
- Microsoft SQL Server 数据库
1. master 数据库 master 数据库记录 SQL Server 系统的所有系统级别信息.它记录所有的登录帐户和系统配置设置.master 数据库是这样一个数据库,它记录所有其它的数据库,其 ...
- [RTOS]--uCOS、FreeRTOS、RTThread、RTX等RTOS的对比之特点
本篇博客就来细数这几个RTOS的特点. 以下内容均来自官方网站或者官方手册Feature的Google翻译的加了我的一些调整,没有任何主观成分. 1. FreeRTOS FreeRTOS是专为 ...
- CentOS虚拟机通过主机网络上网
0 环境简介 环境如下: (1)宿主机为WIN7系统,连接内网,同时通过网关服务器上外网: (2)虚拟机为VMWare12下的CentOS7系统. 宿主机通过WIFI方式上外网的配置方法,参考本人另一 ...