题意:给定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 (扫描线)的更多相关文章

  1. UVaLive 3695 Distant Galaxy (扫描线)

    题意:给平面上的 n 个点,找出一个矩形,使得边界上包含尽量多的点. 析:如果暴力那么就是枚举上下边界,左右边界,还得统计个数,时间复杂度太高,所以我们考虑用扫描线来做,枚举上下边界, 然后用其他方法 ...

  2. 并查集 - UVALive 6889 City Park

    City Park Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=129725 Mean: 在 ...

  3. uvalive 3029 City Game

    https://vjudge.net/problem/UVALive-3029 题意: 给出一个只含有F和R字母的矩阵,求出全部为F的面积最大的矩阵并且输出它的面积乘以3. 思路: 求面积最大的子矩阵 ...

  4. UVALive 6889 City Park 并查集

    City Park 题目连接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=122283#problem/F Description P ...

  5. UVALive - 6864 Strange Antennas 扫描线

    题目链接: http://acm.hust.edu.cn/vjudge/problem/87213 Strange Antennas Time Limit: 3000MS 题意 一个雷达能够辐射到的范 ...

  6. POJ 3277 City Horizon(扫描线+线段树)

    题目链接 类似求面积并..2Y.. #include <cstdio> #include <cstring> #include <string> #include ...

  7. UVALive - 3695 Distant Galaxy

    InputThere are multiple test cases in the input file. Each test case starts with one integer N, (1 ≤ ...

  8. UVaLive 6854 City (暴力)

    题意:给定一个 n*m 的矩阵,表示有多少条道路与它相连,其中有一个-1,表示未知,道路只能横着和竖着,求-1处的值. 析:根据题意可知,一个点,与其他周围的四个点都可能相连的,也就是说肯定有共用道路 ...

  9. bzoj1645 / P2061 [USACO07OPEN]城市的地平线City Horizon(扫描线)

    P2061 [USACO07OPEN]城市的地平线City Horizon 扫描线 扫描线简化版 流程(本题为例): 把一个矩形用两条线段(底端点的坐标,向上长度,添加$or$删除)表示,按横坐标排序 ...

随机推荐

  1. Ubuntu16.04下屏幕侧边栏的设置

    ubnutu的任务栏都是在左侧: zhang@zhang-virtual-machine:~$ gsettings set com.canonical.Unity.Launcher launcher- ...

  2. Python--常用模块部分

    模块 pip install #模块名称 #安装模块 #导入模块 from collections import namedtuple collections模块 提供了几个额外的数据类型: Coun ...

  3. kubernetes容器编排之定义环境变量以及通过downwardapi把pod信息作为环境变量传入容器内

    系列目录 在学习docker的时候,大家可能经常看到不少示例在docker run的时候指定环境变量(比如wordpress的docker示例就是通过环境变量传入账户和密码到容器内).这里之所以经常用 ...

  4. Machine Learning: 一部气势恢宏的人工智能发展史

    转载自:雷锋网 本文作者:陈圳 2016-09-12 09:46 导语:机器学习的从产生,发展,低潮和全盛的历史 雷锋网(公众号:雷锋网)按:本文作者DataCastle数据城堡,主要介绍了机器学习的 ...

  5. SecureCRT 7.0 如何自动记录日志

    设置步骤如下: 1.打开SecureCRT ,在菜单里选择“选项”-->“全局选项”    2.然后选择“常规”--> “默认会话”--> “编辑默认设置”    3.然后选择“日志 ...

  6. Lua_第17 章 数学库

    第17 章 数学库 在这一章中(以下关于标准库的几章中相同)我的主要目的不是对每个函数给出完整地说明,而是告诉你标准库可以提供什么功能.为了可以清楚地说明问题,我可能 会忽略一些小的选项或者行为.基本 ...

  7. JAVA虚拟机、Dalvik虚拟机和ART虚拟机简要对照

    1.什么是JVM? JVM本质上就是一个软件,是计算机硬件的一层软件抽象,在这之上才干够运行Java程序,JAVA在编译后会生成相似于汇编语言的JVM字节码,与C语言编译后产生的汇编语言不同的是,C编 ...

  8. oracle 控制文件多路复用

    网上有很多关于控制文件的操作,我大概看了下.有很多都是炒来炒去转来转去.下面以自己理解和操作为例来对oracle的控制文件进行下介绍. 首先介绍下控制文件 在oralce数据库中,控制文件是一个很小的 ...

  9. 【计蒜客2017NOIP模拟赛1】

    D1T1 题面 题解:一开始以为傻题,旋转个坐标系就行了,结果光荣爆零~ 结果发现旋转坐标系后,由于多了一些虚点,锤子砸到虚点上了~gg [没有代码] D1T2 题面 题解:计算出每个边对答案的贡献即 ...

  10. jQuery处理点击父级checkbox所有子级checkbox都选中,取消选中所有子级checkbox都取消

    注意,每个foreach标签内部都加一个div用来区分各个层次关系,模板代码如下: <foreach name='node' item='v'> <div class='a' ali ...