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;
    }
  • 相关阅读:
    vue-if,vue-show,vue-for指令
    vue计算属性与监听器
    vue属性绑定和双向数据绑定
    C#将JSON文本转换成HttpResponseMessage数据行
    C#数据表(DataTable)转键值对集合
    C# .ToString()格式大全
    C#图片动画效果(旋转360度)异步
    C#利用鼠标绘图
    C#模拟键盘键操作
    C#显示和隐藏鼠标
  • 原文地址:https://www.cnblogs.com/tonix/p/4562576.html
Copyright © 2011-2022 走看看