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 ...
随机推荐
- 项目一:第六天 WebService写接口 和CXF框架
1 课程计划 1. webService入门(了解) 2. 基于jdk1.7开发webservice服务(了解) 3. Apache CXF框架入门(掌握) 4. 基于CXF框架搭建CRM系统(掌握) ...
- 7.25实习培训日志-Oracle SQL(一)
Oracle SQL(一) 重点 尽量避免select *,影响性能,不直观. 慎用Distinct,会排序,影响性能,用exists 排序尽量利用索引,索引有序 索引列不要加函数,会使索引失效 外连 ...
- scrollView用法
在这里记下UIScrollView的用法,一来防止自己忘记,而来再通过这个回顾一下,发现一些新细节. UIScrollView的主要问题在布局上,我现在只用到了内容大小固定额也就是不是tableVie ...
- Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings (容斥原理)
题目链接 Description Yaroslav thinks that two strings s and w, consisting of digits and having length n ...
- Eclipse超级有用的快捷键
1.Alt + Shift + R 重构 2.Ctrl + F11 运行并调试程序 3.Ctrl + Shift + O 自动导入包 4.Ctrl + Shift + F 格式化代码 5.F5 调试模 ...
- Linux——DNS
正向解析和逆向解析 正向域名解析,即DNS解析,是通过域名查询IP的解析方式. 逆向域名解析,即反向DNS解析,是通过IP地址查询域名. [root@localhost ~]# cp /var ...
- How to download a file with plus symbol(+) filename in IIS?
How to download a file with plus symbol(+) filename in IIS? Original post link:https://www.cnblogs.c ...
- bzoj 2827: 千山鸟飞绝
2827: 千山鸟飞绝 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 802 Solved: 228[Submit][Status][Discuss ...
- [Xcode 实际操作]四、常用控件-(2)UIButton图片按钮的使用
目录:[Swift]Xcode实际操作 本文将演示图片按钮的使用 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit class ViewCo ...
- uuid安装 插件安装
yum -y install uuid uuid-devel 安装uuid包tar -zxvf uuid-1.6.1.tar.gzcd uuid-1.6.1./configuremakemake in ...