Untitled
unknown
plain_text
a year ago
3.4 kB
9
Indexable
#include "judge.h"
#include <algorithm>
#include <vector>
using namespace std;
struct Point {
int x;
int y;
int id;
int type;
Point(int _x, int _y, int _id, int _type) : x(_x), y(_y), id(_id), type(_type) {
}
};
class circle : public icircle {
public:
circle() {
points.reserve(N);
}
virtual void addGemstone(int x, int y, int id, int type);
virtual void removeGemstone(int id);
virtual int countGemstones(int x, int y, int r, int type);
virtual int findClosestGemstones(int x, int y, int r, int type, int res[3]);
private:
static constexpr int N = 5e4 + 7;
vector <Point> points;
};
void circle::addGemstone(int x, int y, int id, int type)
{
points.emplace_back(x, y, id, type);
}
void circle::removeGemstone(int id)
{
auto w = std::find_if(points.begin(), points.end(), [id](const Point& p) {
return p.id == id;
});
if(w != points.end()) {
points.erase(w);
}
}
int circle::countGemstones(int x, int y, int r, int type) {
int result = 0;
for (const auto & p : points){
auto d = static_cast<long long>(x - p.x) * (x - p.x) + static_cast<long long>(y - p.y) * (y - p.y);
auto rr = static_cast<long long>(r) * r;
if(d <= rr && (type == 0 || type == p.type)) {
result++;
}
}
return result;
}
int circle::findClosestGemstones(int x, int y, int r, int type, int res[3])
{
vector <pair <long long, int> > results;
for(const auto &p : points) {
auto d = static_cast<long long>(x - p.x) * (x - p.x) + static_cast<long long>(y - p.y) * (y - p.y);
auto rr = static_cast<long long>(r) * r;
if(d <= rr && type == p.type) {
results.emplace_back(d, p.id);
}
}
sort(results.begin(), results.end());
for(size_t i = 0; i < results.size() && i < 3; i++) {
res[i] = results[i].second;
}
return results.size() >= 3 ? 3 : static_cast<int>(results.size());
}
--
#include "judge.h"
#include <iostream>
#include <ctime>
using namespace std;
void judge::run(icircle *c) {
clock_t begin = clock();
int N, OP, X, Y, T, R;
int ans[3];
cin >> N;
int next = 1;
for (int i = 0; i < N; i++) {
cin >> OP;
if (OP == 0) {
cin >> X >> Y >> T;
c->addGemstone(X, Y, next++, T);
}
else if (OP == 1) {
cin >> X;
c->removeGemstone(X);
}
else if (OP == 2) {
cin >> X >> Y >> R >> T;
cout << c->countGemstones(X, Y, R, T) << "\n";
}
else if (OP == 3) {
cin >> X >> Y >> R >> T;
int count = c->findClosestGemstones(X, Y, R, T, ans);
cout << T << ":" << count << " ";
for (int i = 0;i<count;i++) {
cout << ans[i] << " ";
}
cout << "\n";
}
}
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
cout << "TIME: " << elapsed_secs << "\n";
}
--
#pragma warning(disable : 4996)
class icircle
{
public:
virtual void addGemstone(int x, int y, int id, int type) = 0;
virtual void removeGemstone(int id) = 0;
virtual int countGemstones(int x, int y, int r, int type) = 0;
virtual int findClosestGemstones(int x, int y, int r, int type, int res[3]) = 0;
};
class judge
{
public:
static void run(icircle *);
};
--
15
0 3 3 1
0 5 3 5
0 3 5 5
0 5 3 1
0 7 8 1
0 4 1 1
2 4 2 2 1
2 4 2 2 5
2 4 2 4 5
2 4 2 4 0
3 4 2 4 1
3 4 2 4 5
3 4 2 4 6
1 4
2 4 2 2 1
--
3
1
2
5
1:3 6 1 4
5:2 2 3
6:0
2
Editor is loading...
Leave a Comment