pile_layout: update

This commit is contained in:
xuwenyao@laptop 2023-06-02 10:35:25 +08:00
parent 35c824ea78
commit d7168d9620

View File

@ -8,10 +8,8 @@ ROW_RATE = 3
COL_RATE = 10
def matrix(n):
if n < (ROW_RATE * COL_RATE):
r = math.ceil(n / COL_RATE)
else:
r = math.floor(ROW_RATE * ((n / (ROW_RATE * COL_RATE)) ** 0.5))
v = (n / (ROW_RATE * COL_RATE)) ** 0.5
r = int(round(ROW_RATE * v))
c = math.ceil(n / r)
return r, c
@ -32,18 +30,24 @@ def pile_pos(c, n):
def link(c, n):
lst = []
for i in range(n):
lst.append(((i - 1) if i % c != 0 else -1, i))
if i % c != 0:
lst.append(i - 1, i)
else:
lst.append(-1, i)
return lst
def pile_layout(n):
r, c = matrix(n)
print(r, c)
print(station_pos(r))
print(pile_pos(c, n))
print(link(c, n))
def main():
if len(sys.argv) < 2:
print("test.py <n>")
return
n = int(sys.argv[1])
r, c = matrix(n)
print(station_pos(r))
print(pile_pos(c, n))
print(link(c, n))
pile_layout(int(sys.argv[1]))
if __name__ == '__main__':
main()