Instantly share code, notes, and snippets.

# cympfh/aoj1181_biased_dices.cc Created Dec 18, 2014

 #include using namespace std; #define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s)) #define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1)) #define rep(i,n) iota(i,(n),0,1) #define INF (1e9) #define EPS (1e-9) #define cons(a,b) (make_pair(a,b)) #define car(a) (a.first) #define cdr(a) (a.second) #define cadr(a) (car(cdr(a))) #define cddr(a) (cdr(cdr(a))) #define all(a) a.begin(), a.end() #define trace(var) cerr<<">>> "<<#var<<" = "< ostream& operator<<(ostream& os, pair p) { os << '(' << car(p) << ", " << cdr(p) << ')'; return os; } template ostream& operator<<(ostream& os, vector v) { os << v[0]; for (int i=1, len=v.size(); i 3) { return 7 - get_right(7 - u, f); } int *line; if (u == 1) line = dice_line1; if (u == 2) line = dice_line2; if (u == 3) line = dice_line3; for (int i = 0; i < 4; ++i) { if (line[i] == f) return line[-~i % 4]; } assert(false); } int up; int down; int left; int right; int front; int back; Dice (int u, int f) : up(u), front(f) { assert(1 <= u && u <= 6); assert(1 <= f && f <= 6); assert(u != f); assert(u + f != 7); right = get_right(u, f); left = 7 - right; down = 7 - up; back = 7 - front; } void roll(Face f) { if (f == U) return; if (f == D) return; if (f == R) { // roll to right int tmp = up; up = left; left = down; down = right; right = tmp; } else if (f == L) { int tmp = up; up = right; right = down; down = left; left = tmp; } else if (f == F) { int tmp = up; up = back; back = down; down = front; front = tmp; } else if (f == B) { int tmp = up; up = front; front = down; down = back; back = tmp; } assert(up + down == 7); assert(left + right == 7); assert(front + back == 7); } }; ostream& operator<<(ostream& os, Dice d) { os << "(dice " << d.up << ' ' << d.front << ' ' << d.right << ' ' << d.down << ' ' << d.back << ' ' << d.left << ")" << endl; return os; } int main() { for (int n; cin >> n, n; ) { int cx[201][201]; int ux[201][201]; rep (i, 201) { rep (j, 201) { cx[i][j] = 0; ux[i][j] = 0; } } rep (i, n) { //cerr << "# " << i << endl; int u, f; cin >> u >> f; Dice d(u, f); int x = 100; int y = 100; for (;;) { bool b = true; for (int k=6; k>=4; --k) { if (d.front == k && cx[x][y] > cx[x+1][y]) { d.roll(d.F); x++; goto less; } else if (d.right == k && cx[x][y] > cx[x][y+1]) { d.roll(d.R); y++; goto less; } else if (d.back == k && cx[x][y] > cx[x-1][y]) { d.roll(d.B); x--; goto less; } else if (d.left == k && cx[x][y] > cx[x][y-1]) { d.roll(d.L); y--; goto less; } } goto more; less:; //cerr << "roll to " << cons(x-100, y-100) << endl; } more:; //cerr << "at " << cons(x-100, y-100) << endl; ux[x][y] = d.up; cx[x][y]++; } vector count(6, 0); rep (i, 201) { rep (j, 201) { if (ux[i][j] > 0) count[ux[i][j] - 1]++; } } for (int i=0; i<5; ++i) cout << count[i] << ' '; cout << count[5] << endl; } return 0; }