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;
}

最新文章

  1. 【ios开发】使用自定义的TableViewCell
  2. java Properties 配置信息类
  3. jQueryDOM操作笔记
  4. android Activity生命周期(设备旋转、数据恢复等)与启动模式
  5. PHP基础之 数组(二)
  6. Win10 UI线程
  7. [LeetCode] Sparse Matrix Multiplication
  8. BJOI2015 Day1
  9. hdu 2818 Building Block
  10. (C++)String的用法
  11. 简易的WPF MVVM模式开发
  12. 去掉iphone 的圆角样式
  13. Unix/Linux环境C编程新手教程(5) Red Hat Enterprise Linux(RHEL)环境搭建
  14. POJ 2413 How many Fibs?#二分+大数加法
  15. ASCII,Unicode 和通用方式
  16. HTML基础【3】:列表标签
  17. OpenResty安装使用教程(CentOS 6)
  18. Android避免快速双击按钮最简单好用的方式
  19. LINUX7安装Oracle11g单实例小结
  20. leetcode212

热门文章

  1. learning of a previous team
  2. Scrum Meeting 11.05
  3. vim文本处理技巧
  4. Servet3.0于Servlet2.5比较
  5. Answer the questions(回答自己的问题)
  6. 【贪心算法】POJ-3262
  7. excel的常用技巧
  8. [转帖] 知乎: 为什么品牌机器里面的VTX都是关闭的..
  9. Linux服务器学习(二)
  10. 小程序 openid 的原始请求和网络请求