大狗大狗叫叫叫

· · 个人记录

#include<bits/stdc++.h>
#define X first
#define Y second
#define LL long long
#define pLL pair<LL,LL>
using namespace std;
const int N=2e6+5;
pLL P[N];
multiset<pLL>S;
int n;LL D;
inline LL Dis(pLL A,pLL B){return (A.X-B.X)*(A.X-B.X)+(A.Y-B.Y)*(A.Y-B.Y);}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%lld%lld",&P[i].X,&P[i].Y);
    D=Dis(P[1],P[2]),sort(P+1,P+n+1);
    for(int i=1,j=1;i<=n;i++)
    {
        while(D&&D<=(P[j].X-P[i].X)*(P[j].X-P[i].X))S.erase(S.lower_bound({P[j].Y,P[j].X})),j++;
        auto p=S.lower_bound({P[i].Y,P[i].X});
        for(;p!=S.end()&&(p->X-P[i].Y)*(p->X-P[i].Y)<D;p++)D=min(D,Dis(*p,{P[i].Y,P[i].X}));
        p=S.lower_bound({P[i].Y,P[i].X});
        if(p!=S.begin())
        {
            p--;
            for(;(p->X-P[i].Y)*(p->X-P[i].Y)<D;p--)
            {
                D=min(D,Dis(*p,{P[i].Y,P[i].X}));
                if(p==S.begin())break;
            }
        }
        S.insert({P[i].Y,P[i].X});
    }
    printf("%lld\n",D);
}
//Lost the swiss roll and prepare to MuLi MuLi

判断题

1.Dis 函数可以求出两个点的欧几里得距离。

2.第 16 行的 D=Dis(P[1],P[2]) 改为 D=1e18 不会影响程序的时间复杂度。

3.第 21 行的 (p->X-P[i].Y)*(p->X-P[i].Y)<D 删除不会影响程序的时间复杂度。

选择题

4.请问给出以下输入:


3

1 1

1 2

2 2

输出是:

A.4。

B.1。

C.2。

D.3。

5.请问给出以下输入:


5

1 1

1 9

9 1

9 9

0 10

输出是:

A.7。

B.5。

C.2。

D.3。

  1. 这个代码的最坏时间复杂度是:

A.\mathcal O(n\log n)。

B.\mathcal O(n\log^2 n)。

C.\mathcal O(n^2)。

D.\mathcal O(n^2\log n)。