回答編集履歴
2
もっとはやい
test
CHANGED
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
# 追記
|
44
44
|
|
45
|
-
複素数使ったりしながら色々試してたら半分の時間で完了するようになった。。。
|
45
|
+
複素数使ったりしながら色々試してたら半分以下の時間で完了するようになった。。。
|
46
46
|
|
47
47
|
|
48
48
|
|
@@ -51,6 +51,8 @@
|
|
51
51
|
def filterclose(coordinates, distance):
|
52
52
|
|
53
53
|
iterable = iter(coordinates)
|
54
|
+
|
55
|
+
threshold = float(distance)
|
54
56
|
|
55
57
|
a = next(iterable)
|
56
58
|
|
@@ -64,7 +66,7 @@
|
|
64
66
|
|
65
67
|
diff = b_comp - a_comp
|
66
68
|
|
67
|
-
if abs(diff.real) >=
|
69
|
+
if abs(diff.real) >= threshold or abs(diff.imag) >= threshold:
|
68
70
|
|
69
71
|
yield b
|
70
72
|
|
1
より速いコード
test
CHANGED
@@ -37,3 +37,37 @@
|
|
37
37
|
print(b_list) # -> [[802, 1593], [93, 1019], [614, 1019], [1138, 1608], [1128, 1253]]
|
38
38
|
|
39
39
|
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
# 追記
|
44
|
+
|
45
|
+
複素数使ったりしながら色々試してたら半分の時間で完了するようになった。。。
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
```python
|
50
|
+
|
51
|
+
def filterclose(coordinates, distance):
|
52
|
+
|
53
|
+
iterable = iter(coordinates)
|
54
|
+
|
55
|
+
a = next(iterable)
|
56
|
+
|
57
|
+
a_comp = complex(*a)
|
58
|
+
|
59
|
+
yield a
|
60
|
+
|
61
|
+
for b in iterable:
|
62
|
+
|
63
|
+
b_comp = complex(*b)
|
64
|
+
|
65
|
+
diff = b_comp - a_comp
|
66
|
+
|
67
|
+
if abs(diff.real) >= distance or abs(diff.imag) >= distance:
|
68
|
+
|
69
|
+
yield b
|
70
|
+
|
71
|
+
a, a_comp = b, b_comp
|
72
|
+
|
73
|
+
```
|