# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
52629 | Kubalionzzale | Circle selection (APIO18_circle_selection) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <set>
#include <math.h>
#include <algorithm>
#include <functional>
long double abss(long double x)
{
if (x < 0)
return -x;
else
return x;
}
long double sqr(long double x)
{
return x * x;
}
struct compare {
bool operator() (const std::pair<int, int>& lhs, const std::pair<int, int>& rhs) const {
if (lhs.first != rhs.first)
return lhs.first > rhs.first;
else
return lhs.second < rhs.second;
}
};
void firstSubtask(int n)
{
std::set< std::pair<int, int>, compare > set;
int visited[300010] = { 0 };
int x[300010], y[300010], r[300010];
for (int i = 1; i <= n; ++i)
{
std::cin >> x[i] >> y[i] >> r[i];
set.insert(std::make_pair(r[i], i));
}
while (set.empty() == false)
{
std::pair<int, int> p = *set.begin();
set.erase(set.begin());
int xs = x[p.second], ys = y[p.second], rs = r[p.second];
visited[p.second] = p.second;
for (auto it = set.begin(); it != set.end();)
{
std::pair<int, int> sec = *it;
int xq = x[sec.second], yq = y[sec.second], rq = r[sec.second];
long double dist = sqrt(sqr(xq * 1.0 - xs * 1.0) + sqr(yq * 1.0 - ys * 1.0));
// std::cout << p.second << " " << sec.second << " " << dist << " " << rq * 1.0 + rs * 1.0 << "\n";
if (dist <= rq * 1.0 + rs * 1.0)
{
visited[sec.second] = p.second;
it = set.erase(it);
}
else
{
++it;
}
}
}
for (int i = 1; i <= n; ++i)
{
std::cout << visited[i] << " ";
}
}
int main()
{
int n;
std::cin >> n;
if (n <= 5000)
{
firstSubtask(n, x, y, r);
return 0;
}
}