zoukankan      html  css  js  c++  java
  • HackerRank

    More on data structure.

    #include <iostream>
    #include <string>
    #include <vector>
    #include <unordered_map>
    #include <map>
    #include <cmath>
    #include <limits>
    #include <queue>
    using namespace std;
    
    typedef pair<int, int> Point;
    
    struct DistComp
    {
        bool operator()(const Point &p1, const Point &p2)
        {
            long long x1 = p1.first;
            long long y1 = p1.second;
            long long x2 = p2.first;
            long long y2 = p2.second;
    
            return (x1 * x1 + y1 * y1) > (x2 * x2 + y2 * y2);
        }
    };
    
    int main() 
    {
        int n; cin >> n;
        vector<Point> in;
        while (n--)
        {
            int x, y; cin >> x >> y;
            in.push_back(Point(x, y));
        }
    
        map<float, priority_queue<Point, vector<Point>, DistComp>> rec1;
        map<float, priority_queue<Point, vector<Point>, DistComp>> rec2;
    
        for (auto &p : in)
        {
            int x = p.first;
            int y = p.second;
    
            float ret = atan2(y, x);
    
            if (ret >= 0)
            {
                rec1[ret].push(Point(x, y));
            }
            else
            {
                rec2[ret].push(Point(x, y));
            }
        }
    
        for (auto it = rec1.begin(); it != rec1.end(); it++)
        {
            auto &m = it->second;
            while (!m.empty())
            {
                auto p = m.top(); m.pop();
                cout << p.first << " " << p.second << endl;
            }
        }
        for (auto it = rec2.begin(); it != rec2.end(); it++)
        {
            auto &m = it->second;
            while (!m.empty())
            {
                auto p = m.top(); m.pop();
                cout << p.first << " " << p.second << endl;
            }
        }
        return 0;
    }
  • 相关阅读:
    Nexus OSS 3 搭建 Docker & Git LFS 仓库
    YARN FairScheduler
    k8s基本概念及使用
    k8s 基本使用
    10款非常实用的在线网站原型设计工具
    Spark常见问题及性能调优
    spark常见问题处理
    TensorFlow 基本使用
    c语言数组的操作
    在Android开发中遇到的MediaPlayer问题
  • 原文地址:https://www.cnblogs.com/tonix/p/4562576.html
Copyright © 2011-2022 走看看