Find the neutral neutral and the combination IT for the given number

2023-01-26  

Give you a array from small to large with array numbers within [1,1000]. Now you want to delete one of the numbers, but you still want to ensure that you can restore this string of numbers. What is the maximum length you can delete?

Add a 0 on the left and 1001 on the right. The violent enumeration range can be.

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+5;
int n, a[MAXN];
int main()
{
    
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    n++;
    a[n] = 1001;
    int ans = 0, cnt = 1;
    for (int i = 0; i <= n; i++)
    {
    
        for (int j = i+1; j <= n; j++)
        {
    
            if (a[j]-a[i] == j-i) ans = max(ans, j-i-1);
        }
    }
    printf("%d\n", ans);
    return 0;
}
/*
6
1 3 4 5 6 9
*/

source

Related Posts

Read the HDFS directory and display the content in the file on the web page

Parameter transmission (value transmission, reference transfer, pointer transmission) LC

C# Partial Class usage

Ruby On Rails Oracle Configure Oracleenhanced, Ruby-OCI8 installation, ORA-12154: TNS

Find the neutral neutral and the combination IT for the given number

Random Posts

Android database ContentProvider packaging principle L

Sixteen Week OJ Project D: Poinage leading odd number factor

JSOUP parsing the error of the file path of the XML report, perfect solution. Patriotic XML uses JSOUP1. Use JSOUP to complete the analysis of Student.xml, and give the parsed data to the Student object, and finally output the object on the console.

Transplantation WIFI interface

record: My first generation of deep image object recognition