UVaLive 3695 City Game (扫描线)
题意:给定m*n的矩阵,有的是空地有的是墙,找出一个面积最大的子矩阵。
析:如果暴力,一定会超时的。我们可以使用扫描线,up[i][j] 表示从(i, j)向上可以到达的最高高度,left[i][j]表示(i, j) 的左边界,right[i][j]右边界。
这三个可以用递推来实现。从向下扫描,每次更新最大值。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
bool a[maxn][maxn];
int up[maxn][maxn], l[maxn][maxn], r[maxn][maxn]; int main(){
int T; cin >> T;
while(T--){
scanf("%d %d", &n, &m);
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j){
int ch = getchar();
while(ch != 'F' && ch != 'R') ch = getchar();
a[i][j] = ch == 'F' ? false : true;
} int ans = 0;
for(int i = 0; i < n; ++i){
int lo = -1, ro = m;
for(int j = 0; j < m; ++j)
if(a[i][j]) { up[i][j] = l[i][j] = 0; lo = j; }
else{
up[i][j] = i ? up[i-1][j] + 1 : 1;
l[i][j] = i ? max(l[i-1][j], lo + 1) : lo + 1;
}
for(int j = m-1; j >= 0; --j)
if(a[i][j]) r[i][j] = n, ro = j;
else{
r[i][j] = i ? min(r[i-1][j], ro-1) : ro - 1;
ans = max(ans, up[i][j] * (r[i][j] - l[i][j] + 1));
}
}
printf("%d\n", ans * 3);
}
return 0;
}
UVaLive 3695 City Game (扫描线)的更多相关文章
- UVaLive 3695 Distant Galaxy (扫描线)
题意:给平面上的 n 个点,找出一个矩形,使得边界上包含尽量多的点. 析:如果暴力那么就是枚举上下边界,左右边界,还得统计个数,时间复杂度太高,所以我们考虑用扫描线来做,枚举上下边界, 然后用其他方法 ...
- 并查集 - UVALive 6889 City Park
City Park Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=129725 Mean: 在 ...
- uvalive 3029 City Game
https://vjudge.net/problem/UVALive-3029 题意: 给出一个只含有F和R字母的矩阵,求出全部为F的面积最大的矩阵并且输出它的面积乘以3. 思路: 求面积最大的子矩阵 ...
- UVALive 6889 City Park 并查集
City Park 题目连接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=122283#problem/F Description P ...
- UVALive - 6864 Strange Antennas 扫描线
题目链接: http://acm.hust.edu.cn/vjudge/problem/87213 Strange Antennas Time Limit: 3000MS 题意 一个雷达能够辐射到的范 ...
- POJ 3277 City Horizon(扫描线+线段树)
题目链接 类似求面积并..2Y.. #include <cstdio> #include <cstring> #include <string> #include ...
- UVALive - 3695 Distant Galaxy
InputThere are multiple test cases in the input file. Each test case starts with one integer N, (1 ≤ ...
- UVaLive 6854 City (暴力)
题意:给定一个 n*m 的矩阵,表示有多少条道路与它相连,其中有一个-1,表示未知,道路只能横着和竖着,求-1处的值. 析:根据题意可知,一个点,与其他周围的四个点都可能相连的,也就是说肯定有共用道路 ...
- bzoj1645 / P2061 [USACO07OPEN]城市的地平线City Horizon(扫描线)
P2061 [USACO07OPEN]城市的地平线City Horizon 扫描线 扫描线简化版 流程(本题为例): 把一个矩形用两条线段(底端点的坐标,向上长度,添加$or$删除)表示,按横坐标排序 ...
随机推荐
- C递归算法与栈的分析,非全然二叉树遍历分析---ShinePans
对于递归,这里面的分析最好当然是用图形的方式来分析了.这里来总结一下 1.首先对于栈的理解: 先进后出,后进先出 先进后出 2.在进行非全然二叉树的存储之后,我们要做的是对其 ...
- 对JavaBean创建的一点改进
在看了<Effective Java>Item2中对JavaBean的描述后,再结合Item1和Builder模式,遂想有没有其他方式避免JavaBean创建的线程安全问题呢? 以如下Ja ...
- vs2015编译EasyDarwin开源流媒体服务器Linux版本调研
本文转自EasyDarwin团队成员Alex的博客:http://blog.csdn.net/cai6811376/article/details/51843196 之前InfoQ的一篇文章提到用vs ...
- ArcGIS10和ArcGIS10.1关于AO Licence初始化的问题
两个版本主要是esriLicenseProductCode.esriLicenseProductCodeArcInfo和esriLicenseProductCode.esriLicenseProduc ...
- java验证码问题
AuthImageServlet.java package com.util.servlet; import java.awt.Color;import java.awt.Font;import ja ...
- BNUOJ 34978 汉诺塔 (概率dp)
题目分析:对于 i 个盘 , 须要移动多少步,取决于最大的盘子在哪个杆上.在C杆上,则最大的盘不须要移动,由于初始状态一定是满足盘由下到上盘子依次变小的,仅仅须要移动i - 1个盘.假设在A杆上,则首 ...
- 【网络基础系列二】BOOTP、DHCP协议
BOOTP 含义:BOOT Protocol,引导协议 作用:引导无盘计算机或者第一次启动的计算机获取以下网络配置信息: 主机的IP地址.子网掩码 路由器(网关)的IP地址 DNS服务器IP地址 C/ ...
- Handler向子线程发送数据
public class MainActivity extends AppCompatActivity { private static final String TAG = "MainAc ...
- user版本如何永久性开启adb 的root权限【转】
本文转载自:http://blog.csdn.net/o0daxu0o/article/details/52933926 [Solution]* adb 的root 权限是在system/core/a ...
- struts2 学习日记1
struts2 简介 struts2的前身可以说是framework.strut1作为当时很流行的框架,但是有很多的不足之处,framework出生后,它带来了很好的框架,但是很多人已经习惯了stru ...