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过大,会 ...
随机推荐
- ZOJ - 3861 Valid Pattern Lock 【全排列】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3861 思路 先生成全排列,然后判断哪些情况不符合的,剔除就好了 ...
- [egret+pomelo]实时游戏杂记(3)
[egret+pomelo]学习笔记(1) [egret+pomelo]学习笔记(2) [egret+pomelo]学习笔记(3) 服务端的请求流程走完了一遍,下面就该看一下,在目前的服务端中,各服务 ...
- (C)位字段(bit-field)
位字段(bit-field) 在存储空间很宝贵的情况下,有可能需要将多个对象保存在一个机器字中,一种常用的方法是:使用类似于编译器符号表的单个二进制位标志集合,外部强加的数据格式(如设备接口等寄存器) ...
- redhat5.1上安装oracle 10.2g客户端及配置使用
一)安装 1.命令 rpm -q gcc make binutils setarch compat-db compat-gcc compat-gcc-c++ compat-libstdc++ comp ...
- RQNOJ 622 最小重量机器设计问题:dp
题目链接:https://www.rqnoj.cn/problem/622 题意: 一个机器由n个部件组成,每一种部件都可以从m个不同的供应商处购得. w[i][j]是从供应商j处购得的部件i的重量, ...
- 分享知识-快乐自己:论Hibernate中的缓存机制
Hibernate缓存 缓存: 是计算机领域的概念,它介于应用程序和永久性数据存储源之间. 缓存: 一般人的理解是在内存中的一块空间,可以将二级缓存配置到硬盘.用白话来说,就是一个存储数据的容器.我们 ...
- java对象的初始化过程和创建对象的几种方式
1.加载父类,加载父类的静态属性和静态代码块 2.加载子类,加载子类的静态属性和静态代码块 3.初始化父类中的非静态属性并赋初值,执行父类非静态代码块,执行父类构造. 4.初始化子类中的非静态属性并赋 ...
- oracle11g登录等问题
一.oracle 11g登录服务开启 成功安装Oracle 11g后,共有7个服务,这七个服务的含义分别为:1. Oracle ORCL VSS Writer Service:Oracle卷映射拷贝写 ...
- codeforces 659B B. Qualifying Contest(水题+sort)
题目链接: B. Qualifying Contest time limit per test 1 second memory limit per test 256 megabytes input s ...
- 机器学习: R-CNN, Fast R-CNN and Faster R-CNN
做语义分割的大概都知道这几篇文章了,将一个传统的计算机视觉模型,用CNN一点一点的替换,直到最后构建了一个完整的基于CNN的端到端的模型.这几篇文章有一定的连贯性.从中可以看到一种研究的趋势走向. 上 ...