← 返回 meta 的题目列表Random City Name Output Based on Population
类型:online_judge
meta
Given two arrays, one representing city names and the other their corresponding populations. Create a method that randomly outputs a city name with probability proportional to its population. For instance, ny has 7 million people, la has 8 million, and sf has 5 million. ny should be selected with a probability of 7 / (7+8+5).
Input
Array of city names: [ny, la, sf]
Array of populations: [7, 8, 5]
Output
Randomly output a city name, with the probability proportional to its population.
Example
Input
['ny', 'la', 'sf'], [7, 8, 5]