kickstart2019 round_C B. Circuit Board
思路:
这题应该不止一种解法,其中的一种可以看作是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的更多相关文章
- 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 ...
- ZOJ 1648 Circuit Board(计算几何)
Circuit Board Time Limit: 2 Seconds Memory Limit: 65536 KB On the circuit board, there are lots of c ...
- Printed Circuit Board (board)
Printed Circuit Board (board) 题目描述 给出一个N个顶点的简单多边形,对于每个顶点,假如它和原点连成的线段只在这个顶点处和多边形相交,就称为满足要求的顶点.你的任务是输出 ...
- ZOJ1648 Circuit Board(线段相交)
裸的判断线段相交
- bzoj2856: [ceoi2012]Printed Circuit Board
Description 给出一个N个顶点的简单多边形,对于每个顶点,假如它和原点连成的线段只在这个顶点处和多边形相交,就称为满足要求的顶点.你的任务是输出所有满足要求的顶点编号. Input 第一行一 ...
- zoj 1648 Circuit Board
题目:意思就是推断给定的几条线段是否有相交的. 方法:模版吧,有空在来细细学习. 代码: #include <iostream> #include <cstdio> using ...
- COB(Chip On Board) 工艺技术
COX(Chip On X) •X 基板: PCB (Printed circuit board) FPC (Flexible Printed Circuit) Glass •导线焊接 球形焊接 ...
- 分布式系统理论基础 - 一致性、2PC和3PC
引言 狭义的分布式系统指由网络连接的计算机系统,每个节点独立地承担计算或存储任务,节点间通过网络协同工作.广义的分布式系统是一个相对的概念,正如Leslie Lamport所说[1]: What is ...
- xv6课本翻译之——附录A Pc的硬件
Appendix A 附录A PC hardware Pc的硬件 This appendix describes personal computer (PC) hardware, the platfo ...
随机推荐
- http相关理解
http://blog.csdn.net/generon/article/details/73920945
- Ubuntu 安装Logstash
Logstash 包是从同一存储库中可用,如 Elasticsearch,和我们已经安装了该公钥,因此,让我们共创 Logstash 源列表︰ echo 'deb http://packages.el ...
- 阿里巴巴Druid数据库连接池的使用
准备: 创建一个基于SpringBoot的web项目 1 引入相关依赖 jpa.mysql.druid <?xml version="1.0" encoding=" ...
- 使用Cors后台设置WebAPI接口跨域访问
昨天根据项目组前端开发工程师反映,在浏览器端无法直接使用ajax访问后台接口获取数据,根据他的反映,我查阅了相关跨域的解决方案: 一:使用jsonP,但是jsonP只能使用GET请求,完全不符合我项目 ...
- hdu1070
#include <stdio.h>#include <string.h>struct milk{ char brand[128]; int price; int volume ...
- invalid loc header的解决办法
eclipse 运行程序,报invalid loc header,网上一查,删除maven仓库(默认位于%USERPROFILE%\.m2\repository\org)中的下载包,然后重新下载.
- Beta博客总结
描述项目预期计划和现实进展 冲刺 时间 预期任务以及预估时间 现实完成情况以及实际用时 冲刺1 12.4 修改等级答题界面:30,修改获取用户信息接口:30 修改等级答题界面:60,修改获取用户信息接 ...
- MongoDB自定义存储数据库文件位置
mongodb下载地址:https://www.mongodb.com/download-center#community 本机安装目录如下: 配置步骤如下: 1.新建文件夹data(文件夹内再建一个 ...
- Exceptionless - .Net Core开源日志框架
Exceptionless - .Net Core开源日志框架 作者:markjiang7m2 原文地址:https://www.cnblogs.com/markjiang7m2/p/11020140 ...
- Python中print()函数不换行的方法
一.让print()函数不换行 在Python中,print()函数默认是换行的.但是,在很多情况下,我们需要不换行的输出(比如在算法竞赛中).那么,在Python中如何做到这一点呢? 其实很简单.只 ...