思路:

这题应该不止一种解法,其中的一种可以看作是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. Servlet处理流程分析

    ---------------siwuxie095                                 Tomcat 处理客户端请求的方式:     Tomcat 既是一个 Servlet ...

  2. Struts学习第一课 使用Filter作为控制器的MVC应用

    MVC设计模式概览 实现MVC(Model,View,Controller)模式的应用程序由3大部分构成: -模型:封装应用程序的数据和业务逻辑(POJO,Plain Old Java Object) ...

  3. PHP中的继承

    <?php class Bar { private $salary = 3000; public $lunch = 1000; // php中关于“可见性”的概念 public function ...

  4. bzoj2724: [Violet 6]蒲公英(分块)

    传送门 md调了一个晚上最后发现竟然是空间开小了……明明算出来够的…… 讲真其实我以前不太瞧得起分块,觉得这种基于暴力的数据结构一点美感都没有.然而今天做了这道分块的题才发现分块的暴力之美(如果我空间 ...

  5. ssh-ssh整合(Struts2+Sprinig+hibernate)

    在之前呢我们已经讲解过ssm以及ssm2的整合开发,今天我们进行ssh的整合,在之前已经有一篇整合ssh的文章,那是基于注解开发的,今天讲解的为基于配置文件注入方式进行开发.思路:spring管理hi ...

  6. springboot jpa mongodb 多条件分页查询

    public Page<Recorded> getRecordeds(Integer page, Integer size, Recorded recorded) { if (page&l ...

  7. 消息队列RabbitMQ、缓存数据库Redis

    1.RabbitMQ消息队列 1.1 RabbitMQ简介 AMQP,即Advanced Message Queuing Protocol,高级消息队列协议,是应用层协议的一个开放标准,为面向消息的中 ...

  8. java 正则简单使用

    查找是否包含字串 查询是否包含 #{name} 片段 这里有包含所以返回true String context = "select * from t_user where (name = # ...

  9. 利用xsltproc转换jtl报告到html报告

    使用Jmeter测试完后并不能直接生成html报告,而是jtl报告.这里我们可以用xsltproc来解决. xsltproc是由DanielVeillard用来C语言编写的是一个快速XSLT引擎,   ...

  10. Apache服务器配置虚拟域名

    我在别处发的帖子 http://www.52pojie.cn/thread-599829-1-1.html