OIer - FankerWang

一个不正经的信息学博客

Luogu P5086 坐标

原题链接
思路:排序+简单DP,复杂度O(N*logN)

#include<bits/stdc++.h>
using namespace std;
struct node {
    long long x,y,z,k;
}a[1000010];
int a1,b1,c1,d1,n,i,mi,ma;
template <typename T> void read(T &x) {
x = 0; char c = getchar();
for (; !isdigit(c); c = getchar());
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
}
int cmp(node a,node b){
    if (a.x<b.x) return 1;if (a.x>b.x) return 0;
    if (a.y<b.y) return 1;if (a.y>b.y) return 0;
    if (a.z<b.z) return 1;if (a.z>b.z) return 0;
    if (a.k<b.k) return 1;if (a.k>b.k) return 0;
}
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++){
    scanf("%d %d %d %d",&a1,&b1,&c1,&d1);
    a[i].x=b1-a1;a[i].y=c1-b1;a[i].z=d1-c1;a[i].k=i;
  }
sort(a+1,a+1+n,cmp);
mi=INT_MAX;ma=-INT_MAX;
for (int i=2;i<=n;i++)
  if (a[i].x==a[i-1].x&&a[i].y==a[i-1].y&&a[i].z==a[i-1].z){
        if (a[i].k-a[i-1].k<mi) mi=a[i].k-a[i-1].k;
        if (a[i].k+a[i-1].k>ma) ma=a[i].k+a[i-1].k;
    }
printf("%lld %lld\n",mi,ma);
return 0;
}
点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注