2013. Detect Squares
naive
At most 3000 calls in total will be made to add and count
把所有點都去試試看 其他三個點是否存在, 超級窮舉, 3000*3000 => 爆炸
using x, y range, 對角線的想法
0 <= x, y <= 1000
首先紀錄所有點count() 時, 把 input(point[0], point[1])當作 x, y 起點
(i, j) 對角線的點, 其他兩點會是...
for i to 1000
x = point[0], y =point[1]
d = abs(i - x)
so 上對角線的點: (i, j)
j = y+d
i,j [ x, j]
[i, y] x,y
下對角線的點: (i, j)
j = y-d
[i, y] x,y
i, j [x, j]在 x 軸上窮舉 i = 0~1000 : 那距離 d = abs(i-x)
利用這個距離
去算對角線(i, j)(上對角線, 下對角線), 然後去找是不是有符合的其他兩個點
數量就是這三個點的數量乘積
Last updated
Was this helpful?