說明:足球比賽採初、複賽,初賽時將參賽隊伍分成2組(N/2)採單循環(必須與同組各隊比1次)取前一半隊伍進入複賽(N/4),每複賽為單淘汰(勝隊晉級),比賽將頒發前3名。計算所需對賽之場次數目,如N = 16 ,初賽分2組各8對單循環淘汰賽,每組28場計56場,得8隊晉級複賽。8對單淘汰4場4隊晉級,4對單淘汰2場得勝2隊晉級冠軍賽1場,輸的2隊爭季軍賽1場。 合計 56 +4 +2 +1 +1 = 64 場
輸入:16之倍數
輸出:正整數(舉辦之場次數目)
輸入範例:16
輸出範例:64
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x
Print #2, (x / 2) ^ 2
Close #1
Close #2
End Sub
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x
x = x / 2
step = x * (x - 1)
Do Until x = 1
x = x / 2
step = step + x
Loop
Print #2, step + 1
Close #1
Close #2
End Sub
Private Sub Form_Load()
回覆刪除Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
Input #1, N
ans = (N / 2) * (N / 2 - 1)
B = N / 4
For i = 1 To N / 4
ans = ans + B
B = B / 2
If B = 1 Then ans = ans + 2: Print #2, ans: Exit Sub
Next i
Close #2
Close #1
End Sub
阿瑋、Y揚、匿名的高仔好,
回覆刪除這題因為討論過,程式是都沒問題。
不過,用阿瑋的方式,是不是更神奇地容易呢。
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x
x = x / 2
a = x * (x - 1)
Do
x = x / 2
a = a + x
Loop Until x = 1
a = a + 1
Print #2, a
Close #2
Close #1
End Sub
小白好,
回覆刪除程式OK.