初心者のプログラミング日記

プログラミング初心者の日記

プログラミングに関することを書いていきます。

ABC130(A~C)

A - Rounding

かかった時間 2分
実行時間 29ms

X,A=map(int,input().split())

if A>X:
    print(0)
else:
    print(10)

B - Bounding

かかった時間 3分
実行時間 22ms

N,X=map(int,input().split())
L=list(map(int,input().split()))
ans=1
num=0
for i in L:
    num+=i
    if num<=X:
        ans+=1
        
print(ans)

C - Rectangle Cutting

かかった時間 50分
実行時間 24ms

W,H,x,y=map(int,input().split())
cx,cy=W/2,H/2 #中心座標

if x==0 or y==0: #座標(x,y)のどちらかが0を通るなら面積は0
     print((W*H)/2,0)
elif  x==cx and y==cy: #中心座標と(x,y)が同じなら2分割する方法は他にもある
    print((W*H)//2,1)
else: #それ以外
    print((W*H)//2,0)

長方形の中心に座標がない場合は他に2分割する方法はない。
今回のも問題は面積の大きくない方の面積の最大値を出力せよなので、2分割する場合の面積の最大値は縦×横//2なのでそれを出力。
これに気付くまでに時間がかかった。

D問題は尺取り方というのを使うらしいので後日記事にします