Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created September 20, 2016 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/e88c8e354af2a810fef03f64e4d228c6 to your computer and use it in GitHub Desktop.
Save jianminchen/e88c8e354af2a810fef03f64e4d228c6 to your computer and use it in GitHub Desktop.
HackerRank - Stryker code sprint - only 14 minutes to implement - study code #8
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }
struct Point {
int id;
double x, y, z;
};
int main() {
int n; int b;
while(~scanf("%d%d", &n, &b)) {
vector<Point> points(n);
map<int, Point> info;
rep(i, n) {
int id;
double x, y, z;
scanf("%d%lf%lf%lf", &id, &x, &y, &z);
points[i] = { id,x,y,z };
info[id] = points[i];
}
sort(points.begin(), points.end(), [](Point p, Point q) {
return p.z > q.z;
});
map<int, int> loc;
rep(i, n)
loc[points[i].id] = i < b ? 1 : 2;
int head = b;
char ty[2]; int id;
while(~scanf("%s%d", ty, &id)) {
if(toupper(*ty) == 'F') {
if(loc[id] == 1) {
auto p = info[id];
printf("%d = (%.3f,%.3f,%.3f)\n",
id, p.x, p.y, p.z);
} else {
puts("Point doesn't exist in the bucket.");
}
} else if(toupper(*ty) == 'R') {
if(loc[id] == 1) {
if(head == n) {
puts("No more points can be deleted.");
} else {
loc[id] = 3;
loc[points[head ++].id] = 1;
printf("Point id %d removed.\n", id);
}
} else {
puts("Point doesn't exist in the bucket.");
}
} else {
abort();
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment