114 pts 求助(
查看原帖
114 pts 求助(
407417
HerikoDeltana楼主2022/1/3 15:57

从加强版改的,目前只能干到 114 (

#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cstring>

#define Heriko return
#define Deltana 0
#define Romanno 1
#define S signed
#define LL long long
#define R register
#define I inline
#define CI const int
#define mkp(a,b) make_pair(a,b)
#define mst(a,b) memset(a,b,sizeof(a))
#define ON std::ios::sync_with_stdio(false);cin.tie(0)
#define Files() freopen("RNMTQ.in","r",stdin);freopen("RNMTQ.out","w",stdout)

using namespace std;

template<typename J>
I void fr(J &x)
{
    short f(1);
    x=0;
    char c(getchar());

    while(c<'0' or c>'9')
    {
        if(c=='-')
            f=-1;
        
        c=getchar();
    }

    while(c>='0' and c<='9') 
    {
        x=(x<<3)+(x<<1)+(c^=48);
        c=getchar();
    }
   
    x*=f;
}

template<typename J>
I void fw(J x,bool k)
{
    if(x<0)
        x=-x,putchar('-');

    static short stak[35];
    short top(0);

    do
    {
        stak[top++]=x%10;
        x/=10;
    }
    while(x);

    while(top)
        putchar(stak[--top]+'0');

    k?puts(""):putchar(' ');
}

template<typename J>
I J Hmin(const J &x,const J &y)
{
    Heriko x<y?x:y;
}

CI MXX(4e5+1);
const double INF(0x7fffffff);

struct Point
{
    double x,y;

    I bool operator < (const Point &co) const
    {
        Heriko (x==co.x)?(y<co.y):(x<co.x);
    }
}

a[MXX];

I bool CMP(int co,int ro)
{
    Heriko a[co].y<a[ro].y;
}

I double Dist(int co,int ro)
{
    double x((a[co].x-a[ro].x)*(a[co].x-a[ro].x));
    double y((a[co].y-a[ro].y)*(a[co].y-a[ro].y));

    Heriko sqrt(x+y);
}

int tmp[MXX];

double Merge(int l,int r)
{
    double dis(INF);

    if(l==r)
        Heriko dis;

    if(l+1==r)
        Heriko Dist(l,r);

    int mid((l+r)>>1);
    double dl(Merge(l,mid)),dr(Merge(mid+1,r));
    dis=Hmin(dl,dr);

    int top(0);

    for(int i(l);i<=r;++i)
        if(std::fabs(a[mid].x-a[i].x)<dis)
            tmp[++top]=i;

    std::sort(tmp+1,tmp+1+top,CMP);

    for(int i(1);i<=top;++i)
        for(int j(i+1);j<=top and (a[tmp[i]].y-a[tmp[i]].y)<dis;++j)
        {
            double dt(Dist(tmp[i],tmp[j]));
            dis=Hmin(dis,dt);
        }

    Heriko dis;
}


int n;

S main()
{
    // Files();

    fr(n);

    for(int i(1);i<=n;++i)
        scanf("%lf%lf",&a[i].x,&a[i].y);

    std::sort(a+1,a+1+n);
    double ans(Merge(1,n));
    printf("%.0lf\n",ans*ans);

    Heriko Deltana;
}
2022/1/3 15:57
加载中...