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 ...
随机推荐
- JS设置cookie、读取cookie、删除cookie(转)
JS设置cookie.读取cookie.删除cookie 转载 2015-04-17 投稿:hebedich 我要评论 Js操作Cookie总结(设置,读取,删除),工作中经常会用到的哦! ...
- js链表操作
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Freemarker01
1 如何使用freemarker 1.1 导包 freemarker-2.3.19.jar 1.2 创建一个ftl文件作为模板 1.3 创建一个方法来将ftl模板和数据组合起来 2 利用maven实现 ...
- PandaSeq安装报错ltld required, install libtool library
PandaSeq安装 $ ./autogen.sh && ./configure && make && sudo make install PandaS ...
- 19E Fairy
Once upon a time there lived a good fairy A. One day a fine young man B came to her and asked to pre ...
- C#中的new修饰符说明
new修饰符主要是用来隐藏从基类继承的成员. 这句话怎么理解呢,就是说有一个类,它有一个继承类,继承类中存在和基类中一样名称的成员(属性,方法等). 对继承类中的该成员使用new修饰符时,调用时将会隐 ...
- 经典DP 嵌套矩形 (南洋理工ACM—16)
本来是个很水的DP,结果被自己的代码习惯给打败了 代码: #include<iostream> #include<stdlib.h> #include<string.h& ...
- Java 概述及安装使用
Java是什么 概述 java是一种面向对象编程语言,不过经过多年的发展,现在已经演变为了一套强大的技术体系.Java设计者们将Java划分为3种结构独立但却彼此依赖的技术体系分支,它们分别对应着不同 ...
- PHP实现把MySQL数据库导出为.sql文件实例(仿PHPMyadmin导出功能)
1. 首先要得到该数据库中有哪些表,所用函数 mysql_list_tables(),然后可以将获取的所有表名存到一个数组.----------------该函数由于被弃用 用show table ...
- Repeater+AspNetPager+Ajax留言板
最近想要巩固下基础知识,于是写了一个比较简单易懂实用的留言板. 部分样式参考了CSDN(貌似最近一直很火),部分源码参照了Alexis. 主要结构: 1.前期准备 2.Repeater+AspNetP ...