結果

問題 No.172 UFOを捕まえろ
ユーザー MamonboMamonbo
提出日時 2015-10-14 17:53:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,016 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 10,512 KB
実行使用メモリ 7,944 KB
最終ジャッジ日時 2023-08-05 17:31:01
合計ジャッジ時間 1,557 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,760 KB
testcase_01 AC 16 ms
7,920 KB
testcase_02 AC 16 ms
7,784 KB
testcase_03 AC 16 ms
7,920 KB
testcase_04 AC 15 ms
7,736 KB
testcase_05 AC 16 ms
7,772 KB
testcase_06 AC 16 ms
7,920 KB
testcase_07 AC 16 ms
7,872 KB
testcase_08 AC 16 ms
7,784 KB
testcase_09 AC 15 ms
7,924 KB
testcase_10 AC 16 ms
7,864 KB
testcase_11 AC 16 ms
7,820 KB
testcase_12 AC 16 ms
7,944 KB
testcase_13 AC 16 ms
7,832 KB
testcase_14 AC 16 ms
7,772 KB
testcase_15 AC 15 ms
7,828 KB
testcase_16 AC 16 ms
7,764 KB
testcase_17 AC 15 ms
7,760 KB
testcase_18 AC 17 ms
7,924 KB
testcase_19 AC 16 ms
7,764 KB
testcase_20 AC 16 ms
7,812 KB
testcase_21 AC 16 ms
7,816 KB
testcase_22 AC 16 ms
7,876 KB
testcase_23 AC 15 ms
7,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#coding=UTF-8
#思い出した!点と直線の距離の公式だ!
#直線ax+by+c=0について点(x_1,y_1)との距離は
#\frac{|ax_1+by_1+c|}{\root{a^2+b^2}}
#x+y-N=0について(距離)>rになるのは
#|x_1+y_1-N|>\root{2} r
#Nがめちゃくちゃ大きければ閉じ込められるので絶対値の中身は負のときを考えればいい
#N-x_1-y_1>\root{2} r
#N>x_1+y_1+\root{2} r

#4つの直線に囲まれているのは傾きが±になっているを使う
#x+y+N=0のほうは-x-y-N=0とすればよい
#±x_1±y_1+\root{2} rの最大値を求め、それを越える最小の整数を返せばいぇーい

#r in [1,100]なら1.41421ぐらいいれとけば足りるとは思うけどね
mojir=input()
hyo=mojir.split(' ')
x=int(hyo[0])
y=int(hyo[1])
r=int(hyo[2])

#2分探索
kagen=r#以下
jogen=r*2#より大きい
while jogen-kagen>1:
    if ((jogen+kagen)//2)**2 > 2*(r**2):
        jogen=(jogen+kagen)//2
    else:
        kagen=(jogen+kagen)//2

ans=abs(x)+abs(y)+jogen
print(ans)        
0