zoukankan      html  css  js  c++  java
  • Good Bye 2019 B. Interesting Subarray

    链接:

    https://codeforces.com/contest/1270/problem/B

    题意:

    For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a)−min(a)≥k. For example, array [1,3,4,3] isn't interesting as max(a)−min(a)=4−1=3<4 while array [7,3,0,4,3] is as max(a)−min(a)=7−0=7≥5.

    You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist.

    An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.

    思路:

    相邻两个能成立即可。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int MAXN = 2e5+10;
    
    int a[MAXN];
    int n;
    
    int main()
    {
        int t;
        cin >> t;
        while(t--)
        {
            cin >> n;
            for (int i = 1;i <= n;i++)
                cin >> a[i];
            bool flag = false;
            int l, r;
            for (int i = 1;i < n;i++)
            {
                if (abs(a[i]-a[i+1]) >= 2)
                {
                    flag = true;
                    l = i, r = i+1;
                    break;
                }
            }
            if (flag)
                cout << "YES
    " << l << ' ' << r << endl;
            else
                cout << "NO" << endl;
        }
    
        return 0;
    }
    
  • 相关阅读:
    主外键 子查询
    正则表达式
    css3 文本效果
    css3 2d
    sql 基本操作
    插入 视频 音频 地图
    j-query j-query
    document
    js dom 操作
    js
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12122441.html
Copyright © 2011-2022 走看看