关于题目的“加强版”

P1429 平面最近点对(加强版)

STUDENT00 @ 2022-10-28 20:46:13

So,这就是加强版?这份代码能过?!

#include<bits/stdc++.h>
using namespace std;
int n;
struct Node{
    int x,y;
} node[200010];
long long mins=1e18;
bool cmp(Node a,Node b){
    return a.x<b.x;
}
long long dis(int a,int b){
    return  (long long)(node[a].x-node[b].x)*(node[a].x-node[b].x)+(long long)(node[a].y-node[b].y)*(node[a].y-node[b].y);
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d",&node[i].x,&node[i].y);
    sort(node+1,node+n+1,cmp);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=7;j++){
            if(i+j<=n) mins=min(mins,dis(i,i+j));
        }
    }
    printf("%.4lf",sqrt(mins));
    return 0;
}

by bai_tang @ 2022-10-28 20:49:08

@YuRuochen 猜你想找。


by Sprague_Garundy @ 2022-10-28 20:49:24

@YuRuochen 原版是纯暴力都能过。


by STUDENT00 @ 2022-10-28 20:50:09

搞出来了一份贼快的:

#include<bits/stdc++.h>
using namespace std;
int n;
struct Node{
    int x,y;
} node[200010];
long long mins=1e18;
bool cmp(Node a,Node b){
    return a.x<b.x;
}
long long dis(int a,int b){
    return  (long long)(node[a].x-node[b].x)*(node[a].x-node[b].x)+(long long)(node[a].y-node[b].y)*(node[a].y-node[b].y);
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d",&node[i].x,&node[i].y);
    sort(node+1,node+n+1,cmp);
    for(int i=1;i<n;i++){
        mins=min(mins,dis(i,i+1));
        if(i+1<n) mins=min(mins,dis(i,i+2));
        if(i+2<n) mins=min(mins,dis(i,i+3));
    }
    printf("%.4lf",sqrt(mins));
    return 0;
}

by creation_hy @ 2022-12-10 19:25:18

什么人类智慧


|