Skip to content

Instantly share code, notes, and snippets.

@basicxman
Created February 24, 2012 05:22
Show Gist options
  • Select an option

  • Save basicxman/1897963 to your computer and use it in GitHub Desktop.

Select an option

Save basicxman/1897963 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <math.h>
using namespace std;
bool isCrystal(int m, int x, int y) {
int curX = x;
int curY = y;
for (int curM = m; curM > 0; curM--) {
int majorSize = pow(5, curM) / 5;
int mX = curX / majorSize;
int mY = curY / majorSize;
// In solid major cells.
if (mY == 0 && (mX == 1 || mX == 2 || mX == 3)) return true;
if (mY == 1 && mX == 2) return true;
// Out of range major cell.
if (mY == 4 || mY == 3 || mX == 0 || mX == 4) return false;
if (mY == 2 && (mX == 1 || mX == 3)) return false;
curX -= majorSize * mX;
curY -= majorSize * mY;
}
return false;
}
int main(int argc, char **argv) {
freopen("s3.in", "r", stdin);
int n;
scanf("%d\n", &n);
for (int i = 0; i < n; i++) {
int m, x, y;
scanf("%d %d %d\n", &m, &x, &y);
if (isCrystal(m, x, y)) {
cout << "crystal" << endl;
} else {
cout << "empty" << endl;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment