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

問題概要

整数 $\rm{W}$$\rm{B}$ が与えられる。
風船 $n$ 個で $n \times \rm{B}$ g 未満の物体を持ち上げることができる。
体重 $\rm{W}$ kgの高橋君を持ち上げるために必要な風船はいくつか。

体重の単位は[kg]、風船の重さの単位は[g]なので注意。

解法と実装

1. ループを回す

今回は$\rm{W}$の制約が小さいので、ループを回しても間に合います。

for文

W, B = map(int, input().split()) # WとBをint型で受け取る

for i in range(100010): # 制約で存在する答えより大きい数でループを回す
  if W * 1000 < i * B: # 単位を揃えて比較する
    print(i)
    break # 答えを出力したらfor文を終わる

While文

W, B = map(int, input().split()) # WとBをint型で受け取る
i = 1 # 答えの候補(上のnに相当)

while True: # 制約で存在する答えより大きい数でループを回す
  if W * 1000 < i * B: # 単位を揃えて比較する
    print(i)
    break # 答えを出力したらfor文を終わる
  i += 1 # ループ1周ごとにiを1増やす

2. 式を立てて実装する

今回の問題は、$\rm{W} \times 1000 < n \times \rm{B}$を満たす最小の$n$を求める問題となっています。
この$n$$\rm{W} \times 1000 \div \rm{B} + 1$となります。
$\rm{W} \times 1000 \div \rm{B} + 1$とすれば答えが求められます。

W, B = map(int, input().split()) # WとBをint型で受け取る

print((W * 1000) // B + 1) # 答えを出力
0
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
0
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?