2012年11月20日 星期二

音源線III.


這是一種超高科技的音源線,就是有一個輸入端m個輸出端的線。
如今,有人想要在畢旅同時使多台音響播放,請問他需要幾條音源線才夠 ?


輸入說明:
只有一行,代表有n台音響 (0<n<32768),及線的輸出端數量m,(0<m<101)


輸入範例:
5 4

輸出範例:

3 則留言:

  1. Dim linee(100)
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, music, linenum
    linee(0) = linenum
    For i = 0 To 100
    If i <> 0 Then linee(i) = linee(i - 1) + (linenum - 1)
    If linee(i) >= music Then Print #2, i + 1: Exit For
    Next
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  2. Dim x, y As Integer
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, x
    Input #1, y
    Do
    If x < y Then
    Exit Do
    Else
    i = i + 1
    x = x \ y
    End If
    Loop
    Print #2, i
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  3. Dim num() As Integer
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, x, n
    Do
    ReDim Preserve num(r)
    If r = 0 Then
    num(0) = Val(x)
    Else
    num(r) = num(r - 1) + 2
    End If
    r = r + 1
    Loop Until num(r - 1) >= Val(n)
    Print #2, r
    Close #2
    Close #1
    End
    End Sub

    回覆刪除