乐观塔达


私信TA

用户名:uq_65559968553

访问量:563

签 名:

等  级
排  名 5263
经  验 1506
参赛次数 0
文章发表 2
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

解题思路:

没学几天算法  不要喷,就是排序之后  放到队列里,然后扫过去

注意事项:

参考代码:

#include<bits/stdc++.h>

using namespace std;



struct Point {

    long long x;

    long long y;

    long long value;

    int position;

};



bool compareByAngle(const Point& p1, const Point& p2) {

    double angle_a = 1.5708 - atan2(p1.y, p1.x);

    double angle_b = 1.5708 - atan2(p2.y, p2.x);

    if (angle_a < 0) {

        angle_a = 1.5708 * 4 + angle_a;

    }

    if (angle_b < 0) {

        angle_b = 1.5708 * 4 + angle_b;

    }

    if (angle_a == angle_b) {

        double ak1 = p1.x / (double)100000 * p1.x + p1.y / (double)100000 * p1.y;

        double ak2 = p2.x / (double)100000 * p2.x + p2.y / (double)100000 * p2.y;

        return ak1 < ak2;

    }

    return angle_a < angle_b;

}



int main()

{

    int n;

    long long slen;

    cin >> n >> slen;

    vector<int> sequen(n, -1);

    vector<Point> p(n);

    queue<Point> q;

    for (int i = 0; i < n; i++) {

        cin >> p[i].x >> p[i].y >> p[i].value;

        p[i].position = i;

    }

    sort(p.begin(), p.end(), compareByAngle);

    for (int i = 0; i < n; i++) {

        q.push(p[i]);

    }

    int not_stop = 1, num = 0, same = 0;

    double last_angle = -100;

    while(not_stop) {

        not_stop = 0;

        int q_len = q.size();

        for (int i = 0; i < q_len; i++) {

            Point entity = q.front();

            q.pop();

            if (entity.x / (double)slen * entity.x + entity.y / (double)slen * entity.y <= slen) {

                slen += entity.value;

                not_stop = 1;

                if (last_angle != atan2(entity.y, entity.x)) {

                    last_angle = atan2(entity.y, entity.x);

                    num = num + same + 1;

                    same = 0;

                    sequen[entity.position] = num;

                }

                else {

                    sequen[entity.position] = num;

                    same++;

                }

            }

            else {

                q.push(entity);

            }

        }

    }

    for (int& i : sequen) {

        cout << i << " ";

    }

    return 0;

}


 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区