Created
November 9, 2020 02:40
-
-
Save shiracamus/8802f94f7a81447244af76219c13ebac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1181&lang=ja | |
from collections import defaultdict | |
class Die: | |
TOP, FRONT, RIGHT, BACK, LEFT, BOTTOM = 0, 1, 2, 3, 4, 5 | |
ROLL = { | |
TOP: (FRONT, RIGHT, BACK, LEFT), | |
FRONT: (TOP, FRONT, BOTTOM, BACK), | |
RIGHT: (TOP, RIGHT, BOTTOM, LEFT), | |
BACK: (TOP, BACK, BOTTOM, FRONT), | |
LEFT: (TOP, LEFT, BOTTOM, RIGHT), | |
BOTTOM: (FRONT, LEFT, BACK, RIGHT), | |
} | |
def __init__(self, top=1, front=3): | |
if top + front == 7: | |
raise ValueError("never convination top and front") | |
self.faces = [1, 3, 5, 4, 2, 6] # TOP, FRONT, RIGHT, BACK, LEFT, BOTTOM | |
while self.top != top: | |
self.roll(self.FRONT) | |
self.top != top and self.roll(self.RIGHT) | |
while self.front != front: | |
self.roll(self.TOP) | |
def __getitem__(self, face): | |
return self.faces[face] | |
@property | |
def top(self): | |
return self[self.TOP] | |
@property | |
def front(self): | |
return self[self.FRONT] | |
def roll(self, direction): | |
a, b, c, d = self.ROLL[direction] | |
f = self.faces | |
f[b], f[c], f[d], f[a] = f[a], f[b], f[c], f[d] | |
def main(): | |
while True: | |
n = int(input()) | |
if n == 0: | |
break | |
count = [0] * 7 # [1]~[6]は目の個数、[0] は何もない目を減算するために使用 | |
m = defaultdict(int) # サイコロを落とす平面(サイコロのない場所は値が0) | |
for _ in range(n): | |
top, front = map(int, input().split()) | |
die = Die(top, front) | |
x, y, z = 0, 0, 0 # 落とす座標x, y と落ちる高さz | |
while m[x, y, z]: # 落とした場所の高さz=0にサイコロがあれば | |
while m[x, y, z]: # 積み上げてから | |
z += 1 | |
number = 3 # 4,5,6の目で回して落とせる一番大きい目の方向を探す | |
for f, nx, ny in (Die.FRONT, x, y+1), (Die.RIGHT, x+1, y), (Die.BACK, x, y-1), (Die.LEFT, x-1, y): | |
if die[f] > number and m[nx, ny, z] == m[nx, ny, z-1] == 0: | |
number, d, x, y = die[f], f, nx, ny | |
if number == 3: | |
break # 4,5,6の目で回せる方向がなかったのでこの位置で決定 | |
die.roll(d) # 回して | |
z = 0 # 落とす | |
m[x, y, z] = die.top # 平面にサイコロの上面の目(1~6)を積む | |
count[m[x, y, z-1]] -= 1 # ひとつ下の目が隠れるのでカウントを減らす | |
count[m[x, y, z]] += 1 # 積み上げた上面の目のカウントを増やす | |
print(*count[1:]) # 上面に見えている[1]~[6] の目の個数を表示 | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment