2012年11月20日 星期二

音源線II.

這是一種"1公3母"的音源線,就是有一個輸入端三個輸出端的線。
如今,有人想要在畢旅同時使多台音響播放,請問他需要幾條音源線才夠 ?


輸入說明:
只有一行,代表有n台音響 ,  0<n<32768


輸入範例:
2
輸出範例:
1

4 則留言:

  1. Dim linee(100) 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, num
    linee(0) = 3
    For i = 0 To 100
    If i <> 0 Then linee(i) = linee(i - 1) + 2
    If linee(i) >= num Then Print #2, i + 1: Exit For
    Next
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  2. 作者已經移除這則留言。

    回覆刪除
  3. 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

    回覆刪除
  4. 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, n: r = 0
    Do
    ReDim Preserve num(r)
    If r = 0 Then
    num(0) = 3
    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

    回覆刪除