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 07:04:23 浏览: 276
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 each possible mixture of Takahashi's and Aoki's sugar waters. This can be done by iterating through all possible pairs of Takahashi's and Aoki's sugar waters and calculating the concentration of sugar in each mixture.
Once we have the concentration of sugar in each mixture, we can sort them in descending order and select the K-th highest concentration of sugar.
Here's some sample Python code that implements this algorithm:
```
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))
mixtures = []
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
mixtures.append(concentration)
mixtures.sort(reverse=True)
print(mixtures[K-1])
```
Note that this code assumes that the input is well-formed and does not perform any error checking.
阅读全文