Created
September 20, 2016 05:17
-
-
Save jianminchen/652c78955e9999e3ab5759fb9358f69e to your computer and use it in GitHub Desktop.
HackerRank - Point Filtering - study code #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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