Wannafly4 B Distance(最大曼哈顿距离)

传送门

  最大曼哈顿距离模板题

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+10;
struct node
{
    ll x,y;
}nod[maxn];

void proc(ll *p1,ll *p2,int i)
{
    if((i>>1)&1)
        *p1=1;
    else
        *p1=-1;
    if(i&1)
        *p2=1;
    else
        *p2=-1;

}
int main()
{
    int n;
    ll ans=-1;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&(nod[i].y));
        nod[i].y=nod[i].y*nod[i].y;
        nod[i].x=1LL*i*i;
    }
    for(int i=0;i<=3;i++)
    {
        ll x1,x2;
        ll maxx=-9e18,minn=9e18;
        proc(&x1,&x2,i);
        for(int j=1;j<=n;j++)
        {
            ll tmp=x1*nod[j].x+x2*nod[j].y;
            maxx=max(maxx,tmp);
            minn=min(minn,tmp);
        }
        ans=max(ans,maxx-minn);
    }
    printf("%lld\n",ans);
    return 0;
}

 

posted @ 2019-02-12 11:46  eason99  阅读(94)  评论(0编辑  收藏  举报