1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ABC467のPython解答(A~D)

1
Posted at

AtCoder Beginner Contest 467の解答等の速報的まとめ

A問題

誤差が怖いので掛け算で比較
BMIは身長$m$だけど入力の身長は$cm$なので、その分の調整をする

A
h, w = map(int, input().split())

print("Yes" if 25 * h * h <= w * 10000 else "No")

B問題

もらわなかったお釣りを合計

B
n = int(input())
ans = 0

for _ in range(n):
    a, b, s = input().split()
    if s == "keep":
        ans += int(b) - int(a)

print(ans)

C問題

$dp[i][j] = i$番目が$j$ $mod$ $2$の時の加算回数

C
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

if a[0] == 0:
    dp = [0, 1]
else:
    dp = [1, 0]

for a_i, b_i in zip(a[1:], b):
    new_pd = [0, 0]
    if a_i == 0:
        if b_i == 0:
            new_pd[0] = dp[0]
            new_pd[1] = dp[1] + 1
        else:
            new_pd[0] = dp[1]
            new_pd[1] = dp[0] + 1
    else:
        if b_i == 0:
            new_pd[0] = dp[0] + 1
            new_pd[1] = dp[1]
        else:
            new_pd[0] = dp[1] + 1
            new_pd[1] = dp[0]

    dp = new_pd

print(min(dp))

D問題

各円の中心となりうる座標は、2点間の線分の垂直二等分線になる
なので、その直線を求め交差するか確認する

D
INF = float("inf")

def calc_katamuki(ax, ay, bx, by):
    if ay == by:
        return [INF, INF]
    else:
        return [bx - ax, ay - by]

def calc(ax, ay, bx, by):
    k = calc_katamuki(ax, ay, bx, by)
    if k == [INF, INF]:
        return [INF, INF, (ax + bx) , 2]
    else:
        """
        y - (ay+by)/2 = k0/k1(x-(ax+bx)/2)
        y=kx+(ay+by)/2-(k0(ax+bx))/2*k1
        
        """
        return [k[0], k[1], k[1] * (ay + by) - k[0] * (ax + bx), 2 * k[1]]


def same_katamuki(a, b):
    if a[0] == b[0] == INF:
        return True
    elif a[0] == INF or b[0] == INF:
        return False
    else:
        return a[0] * b[1] == b[0] * a[1]


def same_seppen(a, b):
    return a[2] * b[3] == b[2] * a[3]


for _ in range(int(input())):
    px, py, qx, qy, rx, ry, sx, sy = map(int, input().split())

    dy_1 = calc(px, py, qx, qy)
    dy_2 = calc(rx, ry, sx, sy)

    if not same_katamuki(dy_1, dy_2) or same_seppen(dy_1, dy_2):
        print("Yes")
    else:
        print("No")
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?