Frans Bergman 3 年之前
父节点
当前提交
21de83c492
共有 3 个文件被更改,包括 19 次插入0 次删除
  1. 0 0
      7.input
  2. 18 0
      7.py
  3. 1 0
      7.small.input

文件差异内容过多而无法显示
+ 0 - 0
7.input


+ 18 - 0
7.py

@@ -0,0 +1,18 @@
+import statistics
+from util import get_input
+
+input = get_input("7.input")
+
+crabs = [int(a) for a in input[0].split(",")]
+
+median = statistics.median(crabs)
+
+print(sum([abs(a - median) for a in crabs]))
+
+maxpos = max(crabs)
+
+def movecost(a, b):
+    n = abs(a - b)
+    return (n * (n + 1)) / 2
+
+print(min([sum([movecost(a, target) for a in crabs]) for target in range(maxpos + 1)]))

+ 1 - 0
7.small.input

@@ -0,0 +1 @@
+16,1,2,0,4,2,7,1,2,14

部分文件因为文件数量过多而无法显示