LoginSignup
0
0

More than 3 years have passed since last update.

Pythonで毎日AtCoder #14

Last updated at Posted at 2020-03-23

はじめに

前回
14日目

#14

今日はBです。

考えたこと
ABC081-B
ABC081-Bは$A_i$が偶数のときは2で割り切れるまで割ります。奇数のときはすぐにquitしてます。

n = int(input())
a = list(map(int,input().split()))
counter = []
for i in range(n):
    count = 0
    if a[i] % 2 == 0:
        while a[i] % 2 == 0:
            a[i] //= 2
            count += 1
        counter.append(count)
    else:
        print(0)
        quit()

print(min(counter))

ABC087-B
ABC087-Bは思考停止で3重ループしてます。

a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            price = 500 * i + 100 * j + 50 * k
            if price == x:
                ans += 1

print(ans)

ABC083-B
ABC083-BはNが$10^4$程度なので全てのNについて調べています。$1\leq i \leq n$のiをstrにして桁ごとに合計してifで分けています。

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

ans = 0
for i in range(n+1):
    i = str(i)
    k = 0
    for j in range(len(i)):
        k += int(i[j])
    if k <= b and k >= a:
        ans += int(i)

print(ans)

ABC088-B
ABC088-Bはお互いに最適な動きをするので、残っている最大のカードを取ります。なので、sortして1個ずつ合計しています。別にプレイヤーごとに分けなくても、それぞれで差分とってもいい。

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

a.sort(reverse=True)
alice = 0
bob = 0
for i in range(n):
    if i % 2 == 0:
        alice += a[i]
    else:
        bob += a[i]

print(alice-bob)

ABC085-B
ABC085-Bは同じ大きさの餅は置けないので、setで重複無しにしてsortしています。

n = int(input())
d = {int(input()) for _ in range(n)}

d = list(d)
d.sort()
print(len(d))

まとめ

Bくらいは解ける。明日のCからが本番!
では、また

0
0
11

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
0
0