解题思路:
没学几天算法 不要喷,就是排序之后 放到队列里,然后扫过去
注意事项:
参考代码:
#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 人评分
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:944 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:1534 |
printf基础练习2 (C语言代码)浏览:745 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:1466 |
剪刀石头布 (C++代码)浏览:1713 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:509 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:668 |
分糖果 (C语言代码)浏览:920 |
勾股数 (C语言代码)浏览:800 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:459 |