beautiful tree

There are n trees on the street, numbered 1...n, and the height of the ith tree is a i .
Define that n trees are beautiful if and only if
    1. for all i, a i = a n-i+1 ;
    2. for 1 <= i < n / 2 (not divisible), a i + 1 = a i + 1;
say "2 3 4 5 5 4 3 2" and "1 2 3 2 1" are pretty but "1 3 3 1" and "1 2 3 1" are not.
Now please modify the height of at least a few trees (can be larger or smaller), so that these trees are beautiful.

Enter description:

The first line contains an integer n representing the number of trees ( 1 <= n <= 100,000). 
The second line of n integers represents the height of the tree ( 1 <= a

i

<= 100,000)。

Output description:

Output an integer representing the number of heights of the least modified tree.
Example 1

enter

3
2 2 2

output

1
Example 2

enter

4
1 2 2 1

output

0
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) ((a,0,sizeof(a)))
int a[100006],b[200006],c[350006];
int n,m;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    if(n&1) m=n/2+1;
    else m=n/2;
    for(int i=1;i<=m;i++)
        b[i]=i;
    for(int i=m+1;i<=n;i++)
        b[i]=n-i+1;
    memset(c,0,sizeof(c));
    for(int i=1;i<=n;i++)
        c[a[i]-b[i]+200000]++;
    int ans=0;
    for(int i=0;i<=350000;i++)
        years = max(years,c[i]);
    printf("%d\n",n-ans);
    return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325027178&siteId=291194637