Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
HackerRank - Point Filtering - study code #11
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> II;
struct Point {
int k;
double x, y, z;
Point() {};
Point(int k, double x, double y, double z): k(k), x(x), y(y), z(z) {};
bool operator < (const Point &P) const {
return z < P.z;
}
bool operator > (const Point &P) const {
return z > P.z;
}
};
int main() {
#ifdef LOCAL
freopen("Data.inp", "r", stdin);
freopen("Data.out", "w", stdout);
#endif
int n, b; cin >> n >> b;
set<Point> S;
priority_queue<Point> pq;
map<int, Point> Z;
for (int i = 1; i <= n; ++i) {
int k; double x, y, z; cin >> k >> x >> y >> z;
pq.push(Point(k, x, y, z));
Z[k] = Point(k, x, y, z);
}
while (S.size() < b) {
S.insert(pq.top());
pq.pop();
}
string st;
while (cin >> st) {
int k; cin >> k;
if (toupper(st[0]) == 'F') {
if (S.count(Z[k]))
cout << k << " = (" << fixed << setprecision(3) << Z[k].x << "," << Z[k].y << "," << Z[k].z << ")\n";
else
cout << "Point doesn't exist in the bucket.\n";
}
else {
if (S.count(Z[k])) {
if (pq.size()) {
S.erase(Z[k]);
cout << "Point id " << k << " removed." << "\n";
S.insert(pq.top()); pq.pop();
}
else cout << "No more points can be deleted.\n";
}
else
cout << "Point doesn't exist in the bucket.\n";
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.