注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
题目是设计一个职工职位薪金系统,求米,我的答案(1000/1000)如下:
def solution(queries):
workers = {}
worker_times = {}
in_office = {}
promotions = {}
worker_time_detail = {}
double_paid_periods = []
result = []
def merge_double_paid_periods():
if not double_paid_periods:
return
double_paid_periods.sort()
merged_periods = [double_paid_periods[0]]
for start, end in double_paid_periods[1:]:
last_start, last_end = merged_periods[-1]
if start <= last_end: # Overlapping periods
merged_periods[-1] = (last_start, max(last_end, end))
else:
merged_periods.append((start, end))
return merged_periods
for query in queries:
operation = query[0]
if operation == "ADD_WORKER":
workerId, position, compensation = query[1], query[2], query[3]
if workerId in workers:
result.append("false")
else:
workers[workerId] = [(position, compensation, 0)]
worker_times[workerId] = 0
in_office[workerId] = None
worker_time_detail[workerId] = []
result.append("true")
elif operation == "REGISTER":
workerId, timestamp = query[1], int(query[2])
if workerId not in workers:
result.append("invalid_request")
else:
if in_office[workerId] is None:
# Worker is entering
# Apply promotion if applicable
if workerId in promotions and promotions[workerId][2] <= timestamp:
new_position, new_compensation = promotions[workerId][:2]
workers[session
for dp_start, dp_end in double_paid_periods:
if dp_end <= effective_start or dp_start >= effective_end:
continue # Skip non-overlapping periods
dp_effective_start = max(dp_start, effective_start)
dp_effective_end = min(dp_end, effective_end)
session_salary += (dp_effective_end -
dp_effective_start) * int(compensation)
# Adjust the session range for remaining regular time
regular_time_start = dp_effective_end
# Add remaining regular time
session_salary += (effective_end -
effective_start) * int(compensation)
salary += session_salary
result.append(str(salary))
return result |