Skip to content

Instantly share code, notes, and snippets.

@AmitThakur
Last active August 29, 2015 13:59
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 AmitThakur/bcf0ae7c2fbb254a2162 to your computer and use it in GitHub Desktop.
Save AmitThakur/bcf0ae7c2fbb254a2162 to your computer and use it in GitHub Desktop.
Google Code Jam: Qualification Round
// Problem A: Magic Trick | Amit Thakur
#include <cstdio>
#define s(n) scanf("%d", &n)
int magic(int a[][4], int b[][4], int ra, int rb) {
int count(0); int num;
for(int j = 0; j < 4; j++) {
for(int jj = 0; jj < 4; jj++) {
if(a[ra][j] == b[rb][jj]) {
count++;
num = a[ra][j];
}
}
}
if(count == 0) return 33; // cheated
else if(count == 1) return num; // fair case
else if(count > 1) return 22; // bad magician
}
int main() {
int tc; s(tc);
for(int t = 0; t < tc; t++) {
int a[4][4], b[4][4], ra, rb;
s(ra);
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
s(a[i][j]);
}
}
s(rb);
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
s(b[i][j]);
}
}
int d = magic(a, b, ra-1, rb-1);
if(d >= 1 && d <= 16)
printf("Case #%d: %d\n", t + 1, d);
else if(d == 22)
printf("Case #%d: Bad magician!\n", t + 1);
else if(d == 33)
printf("Case #%d: Volunteer cheated!\n", t + 1);
}
return 0;
}
// Problem B. Cookie Clicker Alpha | Amit Thakur
#include <cstdio>
#define s(n) scanf("%lf", &n)
int main() {
int tc; scanf("%d", &tc);
for(int tt = 0; tt < tc; tt++) {
double c, f, x, r(2), t(0);
s(c); s(f); s(x);
while((x / r) > ((c / r) + (x / (r + f)))) {
t += (c / r);
r += f;
}
t += (x / r);
printf("Case #%d: %.7f\n", tt + 1, t);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment