zoukankan      html  css  js  c++  java
  • CodeForces#520 div2 1062A

    题目大意:

      一个递增的数组,每个数字$a_{i}inleft [ 1,10^3 ight ]$,问最多可以擦掉几个数字,仍可以让数组恢复成原来的样子。

    分析:

      比较容易想到,如果一个数字满足$a_{i-1}+1= a_{i},a_{i}+1=a_{i+1}$,那么这个$a_{i}$是可以删除的,为了让头尾也能符合这个普遍规律,我们只需要将$a_{0}=0,a_{n+1}=1001$,然后$i=0$开始,遍历判断是否满足上述条件,如果成立$cnt+1$,否则$cnt=0$,最后再取最大值。

    code:

    #define frp
    
    #include<bits/stdc++.h>
    #include <algorithm>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <string>
    #include <string.h>
    #include <iomanip>
    
    using namespace std;
    typedef long long ll;
    const ll INF = 0x3f3f3f3f;
    const ll inf = 0x7fffff;
    const int maxn = 2e6;
    const int MAXN = 100000 + 5;
    const int MOD = 1e9 + 7;
    
    int a[maxn];
    void solve() {
        int n;
        cin>>n;
        for (int i = 1; i < n+1; ++i) {
            cin>>a[i];
        }
        a[0]=0;a[n+1]=1001;
        int cnt=0,ans=0;
        for (int i = 1; i < n+1; ++i) {
            if(a[i-1]+1==a[i]&&a[i]+1==a[i+1]){
                cnt++;
            }else{
                cnt=0;
            }
    //        cout<<i<<": "<<cnt<<endl;
            ans=max(ans,cnt);
        }
        cout<<ans<<endl;
    }
    
    int main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    #ifdef frp
        freopen("D:\coding\c_coding\in.txt", "r", stdin);
    //    freopen("D:\coding\c_coding\out.txt", "w", stdout);
    #endif
        int t = 1;
    //    cin >> t;
        while (t--) {
            solve();
        }
        return 0;
    }
    

      

  • 相关阅读:
    装饰模式Decorator
    File类
    进程之基础
    IO流
    反射之基础
    20155219 题目补做
    2017-2018-1 20155219 《信息安全系统设计基础》实验三——实时系统
    2017-2018-1 20155219 《信息安全系统设计基础》第九周学习总结
    20155219--pwd指令的简单实现
    2017-2018-1 20155219 《信息安全系统设计基础》第8周学习总结
  • 原文地址:https://www.cnblogs.com/visualVK/p/9978781.html
Copyright © 2011-2022 走看看