1. 正解能得到全對的分數(得2 分)
2. 奧步能拿到半對(得1 分)
3. 放棄的話當然就沒分囉(0 分)
。試問:在時間T 內,用最佳的答題方式,最多可以拿幾分?
輸入說明:
輸入檔第一行說明有幾組測試資料,第二行有兩個整數n 和T,分別代表有幾題,以及總作答時間。接下來n 行每行有兩個整數Ci 和Hi,代表第i 題寫正解需要時間Ci,寫奧步需要時間Hi。其中:- 題目總數n≤100000
- 答題所需時間1≤Hi,Ci≤1000000
- 總作答時間0<, T≤1000000000
輸出說明:
每個測試範例請輸出一個整數,代表最大得分。
輸入範例:
25 12
4 3
6 2
5 3
4 3
5 2
4 10
5 3
6 5
3 1
4 3
輸出範例:
6
5
Dim X()
回覆刪除Dim Y()
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
For i = 1 To N
Input #1, N2, T
ans = 0
ReDim X(N2): ReDim Y(N2)
For j = 1 To N2
Input #1, X(j), Y(j)
Next j
For j = 1 To N2 - 1
For r = j + 1 To N2
If X(j) > X(r) Then
D = X(j)
X(j) = X(r)
X(r) = D
D = Y(j)
Y(j) = Y(r)
Y(r) = D
End If
Next r
Next j
For j = 1 To N2
If (Y(j) / X(j)) <= (1 / 2) And T >= Y(j) Then X(j) = 1000001: ans = ans + 1: T = T - Y(j)
Next j
For j = 1 To N2
If X(j) <> 1000001 And T >= X(j) Then ans = ans + 2: T = T - X(j)
Next j
Print #2, ans
Next i
Close #2
Close #1
End
End Sub
Dim x(), y(), ans, n, AA
回覆刪除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, t
For i = 1 To t
Input #1, m, n
ReDim x(m), y(m)
For j = 1 To m
Input #1, x(j), y(j)
Next
Call A1
Call A11
Call A2
Next
Close
Close
End
End Sub
Sub A1()
For j = 1 To UBound(x)
For i = 1 To UBound(x) - 1
If x(i) > x(i + 1) Then
t3 = x(i): t4 = y(i)
x(i) = x(i + 1): y(i) = y(i + 1)
x(i + 1) = t3: y(i + 1) = t4
End If
Next
Next
End Sub
Sub A11()
For j = 1 To UBound(x)
For i = 1 To UBound(x) - 1
If x(i) = x(i + 1) And y(i) > y(i + 1) Then
t4 = y(i)
y(i) = y(i + 1)
y(i + 1) = t4
End If
Next
Next
End Sub
Sub A2()
AA = 0
ans = 0
For i = 1 To UBound(x)
If ans + x(i) <= n Then ans = ans + x(i): AA = AA + 2 Else If ans + y(i) <= n Then ans = ans + y(i): AA = AA + 1
If ans = n Then Exit For
Next
Print #2, AA
End Sub