-1字节感谢外来专家Erik(使用quick ¥
)
SHð;_P
ṗ3Ç⁼¥Ðf²Ḣ
苍鹭公式的蛮力应用。
在线尝试!(在114个测试用例中达到了60秒超时。在本地花费3m 30秒-它确实检查了114 3 = 1,481,544个三元组)
怎么样?
真正的高尔夫解决方案-给定一个面积,a
它会找到和之间的三个整数的所有元组(即使有重复的三角形且没有面积),获取其面积并过滤具有所需面积的对象(它甚至不会立即停止)找到一个,它将全部翻耕,然后弹出第一个结果)。如果不存在,则产量。1
a
0
SHð;_P - Link 1, get the square of the area of a triangle: list of sides
S - sum the sides (get the perimeter)
H - halve
ð - dyadic chain separation (call that p)
_ - subtraction (vectorises) = [p-side1, p-side2, p-side3]
; - concatenate = [p, p-side1, p-side2, p-side3]
P - product = p*(p-side1)*(p-side2)*(p-side3)
= the square of Heron's formula = area squared
ṗ3Ç⁼¥Ðf²Ḣ - Main link: number a (area)
ṗ3 - third Cartesian power (all triples of [1,area] : [[1,1,1],[1,1,2],[1,2,1],[1,2,2],[2,1,1],[2,1,2],[2,2,1],[2,2,2], ... ,[a,a,a]]
² - square a
Ðf - filter keep if:
¥ - last two links as a dyad:
Ç - call last link (1) as a monad f(list of sides)
⁼ - left (that result) equals right (square of a)?
Ḣ - head - get the first one (an empty list yields 0, perfect for the falsey case)