zoukankan      html  css  js  c++  java
  • Panoramic Photography

    http://codeforces.com/gym/101149/problem/J

    给出n个数字,表示第i条街有a[i]个照片存在过,其中,每个照片可以覆盖一段连续的区间,

    就是一张照片可以覆盖[2, 5]这样,所以第[2, 5]条街出现的次数都要+1

    有点贪心的思想,就是每张照片都要覆盖一段能覆盖的最长的区间(去到0为截止点)

    就像1、2、3、1、2、3

    这样,第一段因该是覆盖[1, 6],然后变成0、1、2、0、1、2

    然后

    [2, 3]

    [3, 3]

    [5, 6]

    [6, 6]

    可以观察发现第i个位置开始的个数是a[i] - a[i - 1],max(0) 修正一下。

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #define IOS ios::sync_with_stdio(false)
    using namespace std;
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    void work() {
        int n;
        cin >> n;
        LL ans = 0;
        LL last = 0;
        for (int i = 1; i <= n; ++i) {
            LL x;
            cin >> x;
            ans += max(0LL, x - last);
            last = x;
        }
        cout << ans << endl;
    }
    
    int main() {
    #ifdef local
        freopen("data.txt","r",stdin);
    #endif
        IOS;
        work();
        return 0;
    }
    View Code
  • 相关阅读:
    驾照更换说明
    批处理创建快捷方式
    AC中保存数据与查询数据
    logger日志模块
    如何将python脚本转化为exe
    numpy学习
    request是个什么东西
    django的test文件的使用方式
    高频正则表达式
    dir 的作用
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/6038705.html
Copyright © 2011-2022 走看看