5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonで競プロに挑む日誌 vol.14 ~max, min 関数の便利な使い方~

Last updated at Posted at 2018-11-02

目標を修正します。

現在の目標

  • 今年の10月内に茶色を取得する
  • ABC の A, B 問題を全部解く←イマココ
  • 年内に緑色を取得する
  • ABC の C, D 問題を全部解く
  • APG4b で C++ にも手を出す

修正後の目標

  • 2018年内に茶色になる←イマココ
  • ABC の A, B 問題を全部解く
  • 2018年度内に緑色を取得する
  • APG4b で C++ にも手を出す

現状

abc.png
A 問題は全完. B 問題を消化中です.

次やること

  • B 問題を解く

#以下、雑感
問題を解く中で、「なるほどなぁ」と思ったことを書いておきます.「双子とスイカ割り」という問題に取り組んだ時、私は最初、下記のように解答しました.

.py
# coding: utf-8
N, A, B = map(int, input().split())
 
p = 0
for _ in range(N):
    si, di = input().split()
    di = int(di)
    if di < A:
        val = A
    elif A<= di <= B:
        val = di
    else:
        val = B
    if si == "West":
        val *= -1
    p += val
 
if p < 0:
    print("West " + str(abs(p)))
elif p > 0:
    print("East " + str(p))
else:
    print(0)

ところが、

.py
    if di < A:
        val = A
    elif A<= di <= B:
        val = di
    else:
        val = B

の部分は、

.py
    val = min(max(A, int(di)), B)

で十分だという解答を見て, 「なるほどなー」と思いました.

5
4
4

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
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?