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;
    }
    
  • 相关阅读:
    E: 无法获得锁 /var/lib/dpkg/lock-frontend
    Ubuntu 18.04 更换apt源
    ubuntu18.04
    小a与“204”------数列、排序
    星际穿越
    合唱团---DP
    分苹果---暴力
    地牢逃脱----DFS搜索最优解
    下厨房---map/字符串查询
    hdu 2654 Be a hero
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12122441.html
Copyright © 2011-2022 走看看