P4889 kls与flag

P4889 kls与flag

一堆杆子, 每个有特定高度 \(a_{i}\) , 现想把杆子弄倒, 可以在一维内往左弄倒和往右弄倒, 求最大优秀对数, 定义优秀对数为两杆倒后顶点重合

Solution

话说见证了这题从蓝变绿又变蓝啊
首先杆子倒下无非两种状态, 向左或向右
我们维护倒下后处在的坐标即可
显然每个杆子有两个坐标, 可以用桶维护
但是数组无法开最大高度 + 所处位置那么大
所以用 \(map\) 当桶即可
o_%e6%97%a0%e6%a0%87%e9%a2%98.png

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

转载于:https://www.cnblogs.com/Tony-Double-Sky/p/9693702.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值