Takahashi and Aoki have N and M bottles of sugar water, respectively. Takahashi's i-th sugar water is composed of A i grams of sugar and B i grams of water. Aoki's i-th sugar water is composed of C i grams of sugar and D i grams of water. There are NM ways to choose one from Takahashi's sugar waters and one from Aoki's and mix them. Among the NM sugar waters that can be obtained in this way, find the concentration of sugar in the sugar water with the K-th highest concentration of sugar. Here, the concentration of sugar in sugar water composed of x grams of sugar and y grams of water is x+y 100x percent. We will ignore saturation.
时间: 2023-05-11 16:04:25 浏览: 239
To find the concentration of sugar in the K-th highest concentration of sugar water, we need to first calculate the concentration of sugar in all possible sugar waters that can be obtained by mixing Takahashi's and Aoki's sugar waters.
We can do this by iterating through all possible combinations of Takahashi's and Aoki's sugar waters, calculating the concentration of sugar in each resulting sugar water, and storing them in a list.
Once we have the list of concentrations, we can sort it in descending order and return the concentration at the K-th index.
Here's some sample Python code to implement this:
```
N = int(input())
M = int(input())
K = int(input())
takahashi = []
for i in range(N):
A, B = map(int, input().split())
takahashi.append((A, B))
aoki = []
for i in range(M):
C, D = map(int, input().split())
aoki.append((C, D))
concentrations = []
for i in range(N):
for j in range(M):
sugar = takahashi[i][0] + aoki[j][0]
water = takahashi[i][1] + aoki[j][1]
concentration = sugar / water * 100
concentrations.append(concentration)
concentrations.sort(reverse=True)
print(concentrations[K-1])
```
Note that this code assumes that the input is formatted as follows:
```
N
M
K
A1 B1
A2 B2
...
C1 D1
C2 D2
...
```
Where N, M, and K are integers, and each Ai, Bi, Ci, and Di are integers representing the grams of sugar and water in each sugar water.
阅读全文