题解 | #小H的小猫#

小H的小猫

https://ac.nowcoder.com/acm/contest/11234/A

要把(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;
}
全部评论

相关推荐

大叔叔1:你把自己说的话打码,所以你想表达什么
点赞 评论 收藏
分享
求内推找工作
在写面经的00后很英俊:别听他们扯犊子说技术栈放前面,你是校招生,把你荣誉证书和项目经历换个位置,你那么多奖,能留住hr的眼光,才会继续看下去
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务