Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
クロック ボード上で( として ) 2 回与えられintた場合、それらの間の最小距離を計算する必要があります。
int
例えば -
d(12,1) = 1 //not 11 d(3,5) = 2 d(10,10) = 0
そのための最速の方法は何ですか?
aとbが から1までの場合12:
a
b
1
12
min(abs(a - b), 12 - abs(a - b))
純粋な算術 (ライブラリなし):
int d(int first, int second){ int temp = first - second; temp < 0? temp *=-1 :temp ; int distance = temp > 6? 12-temp:temp; return distance; }