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过大,会 ...
随机推荐
- render 的执行流程
流程 : render 只能识别 字符串,对于其他的css,html,js,jquery样式是不能识别的,它会将文件中的内容解析称为字符串拿到前端页面,浏览器进行渲染. 例如 : # 视图函数 de ...
- 在Linux下创建7种类型的文件
在测试的时候有时会需要每种类型的文件,在系统中进行搜索都会找到,当然最方便的还是手动创建它们进行测试使用. 普通文件: $ touch regular 目录: $ mkdir directory 符号 ...
- debian支持的系统架构介绍
debian系统支持类型有armel.armhf.i386.amd64.mips.mipsel, powerpc.sparc.s390.s390x等. 详细对比文章见https://www.debia ...
- HDU3336 Count the string —— KMP next数组
题目链接:https://vjudge.net/problem/HDU-3336 Count the string Time Limit: 2000/1000 MS (Java/Others) ...
- 应用程序无法启动(0*c000007b)
2个插件就解决 一个是DX缺失工具检查那个 一个是运行库缺失检查
- wordpress,cos-html-cache静态化后,点击数失效问题的解决方案
装了wordpress cos-html-cache 静态插件后,生成了静态文件,post-views等点击数插件就失效了, 找了一些,包括有个js版本的,需要用到post-views插件,我也不想装 ...
- python 之生成器
斐波拉契数列: In [31]: def func(times): ...: alist = [0,1] ...: sum = 0 ...: for i in range(times): ...: . ...
- 「LOJ#6121」「网络流 24 题」孤岛营救问题(BFS
题目描述 1944 年,特种兵麦克接到国防部的命令,要求立即赶赴太平洋上的一个孤岛,营救被敌军俘虏的大兵瑞恩.瑞恩被关押在一个迷宫里,迷宫地形复杂,但幸好麦克得到了迷宫的地形图.迷宫的外形是一个长方形 ...
- ACM学习历程——UVA10112 Myacm Triangles(计算几何,多边形与点的包含关系)
Description Problem B: Myacm Triangles Problem B: Myacm Triangles Source file: triangle.{c, cpp, j ...
- 【LeetCode】282. Expression Add Operators
题目: Given a string that contains only digits 0-9 and a target value, return all possibilities to add ...