注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
求加米呀~# Say we want to figure out the average speed of cars in different segments of a
# roadway. You might want to do this e.g. for a very simple Google Maps-style
# traffic indicator.
# For simplicity's sake, we can think of the roadway as a line starting at 0 and
# counting upwards. We receive 3 different inputs to either add a speed data for
# individual cars on the roadway, remove a piece of data, or query the average
# speed of a given point. Each car reports its speed along with the segment for
# which its speed was recorded.
# Write a program to handle the input instructions to add/remove data, or output
# the average speed of cars in a given location of the roadway. Feel free to
# define your own input data structure and function signature.
# ```text
# d=0 Roadway
# |---------------------------------------------------->
# Example input visualization (not to scale):
# s=20mph s=15mph
# |---------| |------------|
# 5 10 20 30
# s=30mph
# |-----------|
# 7 15
# Input format:
# I, A, B, S for I=[add, delete], A is the starting location, B is the ending location, S is the speed
# I, A for I=[query], A is the querying location
# end for ending IO 您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 使用VIP即刻解锁阅读权限或查看其他获取积分的方式 游客,您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 VIP即刻解锁阅读权限 或 查看其他获取积分的方式
# Example output explained:
# [5, 7) - 20 mph // 1 car: 20 mph
# [7, 10) - 25 mph // 2 cars: 20 mph and 30 mph
# [10, 15) - 30 mph // 1 car: 30 mph
# [20, 30) - 15 mph // 1 car: 15 mph
# ```
"""
cars[s, e, speed]
iterate through list of cars, if point between start and end, add speed to average |