要把(0,0)围在墙角,很容易想到至少要有两个点分别在x轴和y轴上的点,这里对所给的n个点按照x坐标和y坐标排序一遍,然后找到两个在坐标轴上的点即可求出答案
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
typedef pair<double, double> PDD;
const int N = 1000010;
int n;
PDD psx[N], psy[N];
int main(void)
{
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
double x, y;
scanf("%lf%lf", &x, &y);
psx[i] = {x, y};
psy[i] = {y, x};
}
PDD ans_y = {0.0, 0.0};
PDD ans_x = {0.0, 0.0};
sort(psx, psx + n);
sort(psy, psy + n);
//找x轴上的点
for(int i = 0; i < n ;i++)
{
if(psx[i].first != 0.0 && psx[i].second == 0.0)
{
ans_x = psx[i];
break;
}
}
//找y轴上的点
for(int i = 0; i < n; i++)
{
if(psy[i].first != 0.0 && psy[i].second == 0.0)
{
ans_y = psy[i];
break;
}
}
if(ans_x.first != 0.0 && ans_y.first != 0.0)
{
double x = ans_x.first, y = ans_y.first;
double d = sqrt(x * x + y * y);
printf("%.10lf\n", d);
}
else
{
printf("Poor Little H!\n");
}
return 0;
}


京公网安备 11010502036488号