LoginSignup
1
0

More than 1 year has passed since last update.

AtCoder Beginner Contest 206(Sponsored by Panasonic)参戦記(三完)

Posted at

A問題

https://atcoder.jp/contests/abc206/tasks/abc206_a
税抜き$n$円のものがあります。税込価格では$206$円以上か以下かちょうど$206$円かを求めてください。

誤差を考えなくとも良いです。
また、税込価格を求めるときにはmath.floor()を使いました。

n = int(input())

import math

if math.floor(n * 1.08) < 206:
    print("Yay!")
elif math.floor(n * 1.08) == 206:
    print("so-so")
else:
    print(":(")

B問題

https://atcoder.jp/contests/abc206/tasks/abc206_b
貯金をしたいです。$i$日目には$i$円貯金します。
貯金が$n$円貯めるには、最低何日かかるでしょうか。

1日目から順々にシュミレーションすればよいです。
こういうときはwhileを使うことによってきれいに書けます。

n = int(input())

d = 1
y = 0

while y < n:
    y += d
    d += 1

print(d - 1)

C問題

https://atcoder.jp/contests/abc206/tasks/abc206_c
$N$項からなる数列があります。
$A_i$と$A_j$が異なる整数$i, j$$(i < j)$の組が何通りあるかを求めてください。

ソートしてごにょごにょやります。
より詳しく言うと、ソートすると同じ整数が並んだ状態になるので、やりやすくなりますね。

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

a.sort()

d = 0
ans = 0

for i in range(1, n):
    if a[d] != a[i]:
        d = i
    ans += d

print(ans)

終わりに

image.png
冷えました。悲しいです。
いい加減Dを解けるようになりたいものです。
ちなみに、Cの制約を誤読していて、ソートすると間に合わないと思っていました。
ちゃんと制約を見ましょう(自戒)

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