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?

【Swift】AtCoderABC428 A問題

Posted at

概要

  • AtCoder ABC428におけるA問題「Grandma’s FootStep」のSwiftによる解説

該当の問題

コード

import Foundation

let array = readLine()!.components(separatedBy: " ").map{Int($0)!}
let S = array[0] //7
let A = array[1] //3
let B = array[2] //2
let X = array[3] //11

let correct = S * ((X / (A + B)) * A + min(A, X % (A + B)))

print(correct)

解説

  • 7*((11/(3+2))*3 + (11%(3+2)と3を比較して小さいほう))

敗因

  • A+BのセットをXで割った値と余りをSで掛ける。という発想までは辿り着けていたが、端数処理を正確に求める実装方法を知らなかったこと。
  • X=11を箱に見立ててforループの中で各箱をBoolで判定するなどという非効率なことを行ってしまい、大幅なロスとなってしまった。
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?