CF – Light It Up(前缀和)

http://codeforces.com/contest/1000
一道前缀和傻逼题调半天

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int a[maxn], dif[maxn];
ll pre[2][maxn], suf[2][maxn];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, len;
    cin >> n >> len;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    a[n + 1] = len;//a里是每个lit的位置
    //dif[i]为第i个和第i-1个lit的距离
    for (int i = 1; i <= n + 1; ++i) dif[i] = a[i] - a[i - 1];
    //pre[1][1]存前两个lit的距离(1和0),之后[0][2]存2和1的距离,然后[1][3]存3和2的距离
    for (int i = 1; i <= n + 1; ++i) pre[i & 1][i] = a[i] - a[i - 1];
    //现在suf和pre对应起来了
    for (int i = n + 1; i >= 1; --i) suf[i & 1][i] = a[i] - a[i - 1];
    //一个求前缀和一个求后缀和
    for (int i = 1; i <= n + 1; ++i) pre[0][i] += pre[0][i - 1], pre[1][i] += pre[1][i - 1];
    for (int i = n; i >= 0; --i) suf[0][i] += suf[0][i + 1], suf[1][i] += suf[1][i + 1];

    //啥都不干
    ll ans = pre[1][n + 1];
    for (int i = 1; i <= n + 1; ++i){
        //枚举每个间隔,如果间隔大于1,可以放在间隔开头或结尾,同时使后面的和取反,但是总和要减1
        //根据上面的定义,1是不管,0是取反,取反只会取反后缀,所以这样写就完事了
        //注意i要遍历到i+1表示最后一个间隔
        if (dif[i] > 1) ans = max(ans, pre[1][i - 1] + suf[0][i + 1] + dif[i] - 1);
    }
    cout << ans << endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
rfc是网络协义的重要学习资源,为方便大家查看,特收藏整理如下。下面是其中一篇内容: Network Working Group Steve Crocker Request for Comments: 1 UCLA 7 April 1969 Title: Host Software Author: Steve Crocker Installation: UCLA Date: 7 April 1969 Network Working Group Request for Comment: 1 CONTENTS INTRODUCTION I. A Summary of the IMP Software Messages Links IMP Transmission and Error Checking Open Questions on the IMP Software II. Some Requirements Upon the Host-to-Host Software Simple Use Deep Use Error Checking III. The Host Software Establishment of a Connection High Volume Transmission A Summary of Primitives Error Checking Closer Interaction Open Questions Crocker [Page 1] RFC 1 Host Software 7 April 1969 IV. Initial Experiments Experiment One Experiment Two Introduction The software for the ARPA Network exists partly in the IMPs and partly in the respective HOSTs. BB&N has specified the software of the IMPs and it is the responsibility of the HOST groups to agree on HOST software. During the summer of 1968, representatives from the initial four sites met several times to discuss the HOST software and initial experiments on the network. There emerged from these meetings a working group of three, Steve Carr from Utah, Jeff Rulifson from SRI, and Steve Crocker of UCLA, who met during the fall and winter. The most recent meeting was in the last week of March in Utah. Also present was Bill Duvall of SRI who has recently started working with Jeff Rulifson. Somewhat independently, Gerard DeLoche of UCLA has

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值