zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 88 (Rated for Div. 2) D、Yet Another Yet Another Task

    题意:

    给你一个含n个数a1,a2...an的数组,你要找到一个区间[l,r],使得al+a(l+1)+...+a(r-1)+ar减去max(al,a(l+1),...,a(r-1),ar)的值尽可能大

    n<=1e5

    -30<=ai<=30

    题解:

    因为ai的范围特别小,我们可以枚举区间[l,r]的最大值,然后就是暴力循环(这一点看代码)

    代码:

    #include<stdio.h>
    #include<algorithm>
    #include<iostream>
    #include<string>
    #include<queue>
    #include<deque>
    #include<string.h>
    #include<map>
    #include <iostream>
    #include <math.h>
    #define Mem(a,b) memset(a,b,sizeof(a))
    const double II = acos(-1);
    const double PP = (II*1.0)/(180.00);
    using namespace std;
    typedef long long ll;
    const int INF=0x3f3f3f3f;
    const int maxn=2e5+10;
    const double eps=1e-6;
    const double PI=acos(-1);
    int v[maxn];
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            cin >> v[i];
        }
        int sum = 0;
        int ans = 0;
        for (int i = 0; i <= 30; i++)  //ö�����������ֵ
        {
            sum = 0;
            for (int j = 1; j <= n; j++)
            {
                if( v[j] > i ) sum = 0;
                else
                {
                    sum += v[j];
                    if( sum < 0 ) sum = 0;
                    ans = max(ans,sum-i); //��������
                }
            }
        }
        cout << ans << '
    ';
        return 0;
    }
  • 相关阅读:
    关于data初始化值
    switch的优化替代写法
    phpstorm安装xdebug
    如何将一个列表封装为一个树形结构
    Win10系统桌面图标距离间距变大的问题
    cnpm无法加载文件的问题
    0、springboot
    1、springboot2新建web项目
    Game游戏分析
    netty学习
  • 原文地址:https://www.cnblogs.com/kongbursi-2292702937/p/13361447.html
Copyright © 2011-2022 走看看