思路:

这题应该不止一种解法,其中的一种可以看作是leetcode85https://www.cnblogs.com/wangyiming/p/11059176.html的加强版:

首先对于每一行,分别使用滑动窗口法将这一行划分成符合题目定义的若干合法子段s1, s2, s3, ...。对于每一段si,从起点到终点分别将每个元素分别编号为1, 2, 3, ..., |si|。

例如:

2 2 4 4 20
8 3 3 3 12
6 6 3 3 3
1 6 8 6 4

可以转化成

1 2 1 2 1
1 1 2 3 1
1 2 1 2 3
1 1 1 1 1

接下来就可以将此矩阵转置,使用leetcode85的思路进行计算了:

1 2 1 2 1
1 1 2 3 1
1 2 1 2 3
1 1 1 1 1

实现:

 #include <bits/stdc++.h>
using namespace std;
const int N = ;
int a[N][N], b[N][N];
int main()
{
int T, r, c, k;
cin >> T;
for (int t = ; t <= T; t++)
{
memset(b, 0x3f, sizeof b);
cin >> r >> c >> k;
for (int i = ; i < r; i++)
for (int j = ; j < c; j++)
cin >> a[i][j];
for (int i = ; i < r; i++)
{
map<int, int> mp;
int f = , s = ;
while (f < c)
{
while (f < c)
{
if (!mp.count(a[i][f])) mp[a[i][f]] = ;
mp[a[i][f]]++;
if (mp.rbegin()->first - mp.begin()->first > k) break;
b[i][f] = f - s + ;
f++;
}
while (s < f && mp.rbegin()->first - mp.begin()->first > k)
{
if (mp[a[i][s]] == ) mp.erase(a[i][s]);
else mp[a[i][s]]--;
s++;
}
b[i][f] = f - s + ;
f++;
}
}
int ans = ;
for (int j = ; j < c; j++)
{
stack<pair<int, int>> sta;
vector<int> pre;
for (int i = ; i < r; i++)
{
while (sta.size() && sta.top().first >= b[i][j]) sta.pop();
if (!sta.empty()) pre.push_back(sta.top().second + );
else pre.push_back();
sta.push(make_pair(b[i][j], i));
}
while (sta.size()) sta.pop();
for (int i = r - ; i >= ; i--)
{
while (sta.size() && sta.top().first >= b[i][j]) sta.pop();
if (!sta.empty()) ans = max(ans, (sta.top().second - pre[i]) * b[i][j]);
else ans = max(ans, b[i][j] * (r - pre[i]));
sta.push(make_pair(b[i][j], i));
}
}
cout << "Case #" << t << ": " << ans << endl;
}
return ;
}

kickstart2019 round_C B. Circuit Board的更多相关文章

  1. ZOJ1648 Circuit Board 2017-04-18 20:31 34人阅读 评论(0) 收藏

    Circuit Board Time Limit: 2 Seconds      Memory Limit: 65536 KB On the circuit board, there are lots ...

  2. ZOJ 1648 Circuit Board(计算几何)

    Circuit Board Time Limit: 2 Seconds Memory Limit: 65536 KB On the circuit board, there are lots of c ...

  3. Printed Circuit Board (board)

    Printed Circuit Board (board) 题目描述 给出一个N个顶点的简单多边形,对于每个顶点,假如它和原点连成的线段只在这个顶点处和多边形相交,就称为满足要求的顶点.你的任务是输出 ...

  4. ZOJ1648 Circuit Board(线段相交)

    裸的判断线段相交

  5. bzoj2856: [ceoi2012]Printed Circuit Board

    Description 给出一个N个顶点的简单多边形,对于每个顶点,假如它和原点连成的线段只在这个顶点处和多边形相交,就称为满足要求的顶点.你的任务是输出所有满足要求的顶点编号. Input 第一行一 ...

  6. zoj 1648 Circuit Board

    题目:意思就是推断给定的几条线段是否有相交的. 方法:模版吧,有空在来细细学习. 代码: #include <iostream> #include <cstdio> using ...

  7. COB(Chip On Board) 工艺技术

    COX(Chip On X) •X 基板:  PCB (Printed circuit board)  FPC (Flexible Printed Circuit)  Glass •导线焊接 球形焊接 ...

  8. 分布式系统理论基础 - 一致性、2PC和3PC

    引言 狭义的分布式系统指由网络连接的计算机系统,每个节点独立地承担计算或存储任务,节点间通过网络协同工作.广义的分布式系统是一个相对的概念,正如Leslie Lamport所说[1]: What is ...

  9. xv6课本翻译之——附录A Pc的硬件

    Appendix A 附录A PC hardware Pc的硬件 This appendix describes personal computer (PC) hardware, the platfo ...

随机推荐

  1. [dp]LCS最长公共子序列

    https://www.51nod.com/tutorial/course.html#!courseId=4 复杂度:${\rm O}(nm)$ 转移方程: #include<bits/stdc ...

  2. Flask05 cookie、类视图、方法视图、自己的404页面

    1 什么是cookie 就是网站存放到你浏览器中的一部分固定内容:当你下次访问我这个网站的时候,你会把之前我存放到你浏览器中的数据带回来给我        你要先登录(用户名.密码) ->   ...

  3. error C2872: “flann”: 不明确的符号 --- PCL 与OpenCV2 的flann命名空间冲突问题的解决方法

    error C2872: "flann": 不明确的符号 - PCL 与OpenCV2命名空间冲突问题的解决方法 error C2872: "flann" 如果 ...

  4. Entity Framework Code-First(10.1):EntityTypeConfiguration

    EntityTypeConfiguration Class in Code-First: Before we start to configure using Fluent API, let's se ...

  5. Note: Differentially Private Access Patterns for Searchable Symmetric Encryption

    The Core Issues and Ideas of This Paper Problem Baseline Searchable Symmetric Encryption (SSE) could ...

  6. SAS笔记(2) RETAIN语句

    本文重点: 使用RETIAN,INPUT在每次循环执行时保留上一次PDV中的变量值. SUM语句和SET语句会自动RETAIN变量. 1. RETAIN语句 1.1 Example 1 先来看看在DA ...

  7. Codeforces Round #527 (Div. 3)F(DFS,DP)

    #include<bits/stdc++.h>using namespace std;const int N=200005;int n,A[N];long long Mx,tot,S[N] ...

  8. Bigdecimal 比较equals与compareTo

    原文链接:https://blog.csdn.net/jixinhuluwa/article/details/72626598 1.b.equals(BigDecimal.ZERO); 该方法存在的问 ...

  9. 洛谷P5058 [ZJOI2004]嗅探器

    题目描述 某军搞信息对抗实战演习,红军成功地侵入了蓝军的内部网络,蓝军共有两个信息中心,红军计划在某台中间服务器上安装一个嗅探器,从而能够侦听到两个信息中心互相交换的所有信息,但是蓝军的网络相当的庞大 ...

  10. 2017 ACM/ICPC Asia Regional Shenyang Online number number number

    题意:求n个斐波那契数列组合都无法得到的最小数字 解法: 1 我们先暴力的求出前面几个数字 2 然后再暴力的求递推 3 接着矩阵快速幂(没写错吧?) /*#include<bits/stdc++ ...