Subscribed unsubscribe Subscribe Subscribe

0w1

CFR 795 C. Maximum Number ( Greedy )

Problem - C - Codeforces

題意:
你有無限多個七段顯示器,問不超過 n 個段可以發光的前提下,可構成的最大數字是多少。

制約:
The first line contains the integer n (2 ≤ n ≤ 100 000) — the maximum number of sections which can be highlighted on the display.

解法:
越多數位越好,所以選 1 最好。但如果 n 是奇數,頭先放一個 7。

時間 / 空間複雜度:
O( N )

object Main extends App {
  val cost = Array( 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 )
  var N = readInt // keyword val seems to work like const, in contrast to var
  if( N % 2 == 1 ) {
    print( 7 )
    N -= 3
  }
  while( N > 0 ) {
    print( 1 )
    N -= 2
  }
  println()
}