P4889 kls与flag
2024-08-28 09:30:10
P4889 kls与flag
一堆杆子, 每个有特定高度 \(a_{i}\) , 现想把杆子弄倒, 可以在一维内往左弄倒和往右弄倒, 求最大优秀对数, 定义优秀对数为两杆倒后顶点重合
Solution
话说见证了这题从蓝变绿又变蓝啊
首先杆子倒下无非两种状态, 向左或向右
我们维护倒下后处在的坐标即可
显然每个杆子有两个坐标, 可以用桶维护
但是数组无法开最大高度 + 所处位置那么大
所以用 \(map\) 当桶即可
Code
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<climits>
#include<map>
#define LL long long
using namespace std;
LL RD(){
LL out = 0,flag = 1;char c = getchar();
while(c < '0' || c >'9'){if(c == '-')flag = -1;c = getchar();}
while(c >= '0' && c <= '9'){out = out * 10 + c - '0';c = getchar();}
return flag * out;
}
const LL maxn = 400019;
LL num, m, cnt;
map<LL, LL>ton;
int main(){
num = RD(), m = RD();
for(LL i = 1;i <= num;i++){
LL a = RD();
cnt += ton[i - a];
cnt += ton[i + a];
ton[i - a]++, ton[i + a]++;
}
printf("%lld\n", cnt);
return 0;
}
最新文章
- 【ios开发】使用自定义的TableViewCell
- java Properties 配置信息类
- jQueryDOM操作笔记
- android Activity生命周期(设备旋转、数据恢复等)与启动模式
- PHP基础之 数组(二)
- Win10 UI线程
- [LeetCode] Sparse Matrix Multiplication
- BJOI2015 Day1
- hdu 2818 Building Block
- (C++)String的用法
- 简易的WPF MVVM模式开发
- 去掉iphone 的圆角样式
- Unix/Linux环境C编程新手教程(5) Red Hat Enterprise Linux(RHEL)环境搭建
- POJ 2413 How many Fibs?#二分+大数加法
- ASCII,Unicode 和通用方式
- HTML基础【3】:列表标签
- OpenResty安装使用教程(CentOS 6)
- Android避免快速双击按钮最简单好用的方式
- LINUX7安装Oracle11g单实例小结
- leetcode212