数据有点弱啊

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

A星际穿越 @ 2018-10-26 16:04:04

这么明显的错误贪心代码都可以A掉。。。

//from https://www.cnblogs.com/jaywang/p/7719038.html
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
template<class T>inline void read(T &_a)
{
    char _ch=getchar();_a=0;
    while(_ch<'0'||_ch>'9')_ch=getchar();
    while(_ch>='0'&&_ch<='9'){_a=(_a<<3)+(_a<<1)+_ch-'0';_ch=getchar();}
}

const int maxn=200001;
struct fff
{
    int x,y;
    inline bool operator < (const fff xx) const {return x<xx.x;}
}node[maxn];
int n;
double ans=2000000000;

double calc(int x1,int y1,int x2,int y2)
{
    return sqrt(pow((double)(x1-x2),2)+pow((double)(y1-y2),2));
}

inline bool cmp(fff a,fff b)
{
    return a.y<b.y;
}

int main()
{
    read(n);
    for (register int i=1;i<=n;++i) read(node[i].x),read(node[i].y);
    sort(node+1,node+n+1);
    for (register int i=1;i<n;++i)
        ans=min(ans,calc(node[i].x,node[i].y,node[i+1].x,node[i+1].y));
    sort(node+1,node+n+1,cmp);
    for (register int i=1;i<n;++i)
        ans=min(ans,calc(node[i].x,node[i].y,node[i+1].x,node[i+1].y));
    printf("%.4lf",ans);
    return 0;
}

一组明显的hack数据

6
0 6
6 0
5 5
8 8
13 7
7 13


by A星际穿越 @ 2018-10-26 16:05:01

@chen_zhe


by chen_zhe @ 2018-10-26 16:20:31

@A星际穿越 added 感谢您的贡献


by A星际穿越 @ 2018-10-26 16:21:57

@chen_zhe 其实不一定要添加我这组数据,稍微大一点也可以


by A星际穿越 @ 2018-10-26 16:25:37

@chen_zhe 比如他的数据

https://www.luogu.org/discuss/show/76127


by A星际穿越 @ 2018-10-26 16:26:00

虽然我没试过


|