AcWing 3238. 工资计算
原题链接
简单
作者:
不知名_4
,
2024-04-01 23:36:16
,
所有人可见
,
阅读 1
python 代码
n = int(input())
# 150900---最大税后工资对应的税前工资,如果没算错的话
l,r = n,160000
def compute(s):
if s<=3500:
return s
floors = [[0,1500], [1500,4500], [4500,9000], [9000,35000], [35000,55000], [55000,80000]]
tax_percentage = [0.03, 0.1, 0.2, 0.25, 0.3, 0.35] #超过80000的部分的税率为0.45
a = s - 3500
tax = 0
for i in range(6):
if a < floors[i][0]:
break
if a >= floors[i][0] and a < floors[i][1]:
tax += (a-floors[i][0])*tax_percentage[i]
elif a >= floors[i][0] and a >= floors[i][1]:
tax += (floors[i][1]-floors[i][0])*tax_percentage[i]
if a>80000:
tax += (a-80000)*0.45
return s-tax
while l<r:
mid = l+r>>1
if compute(mid) > n:
r = mid
elif compute(mid) < n:
l = mid+1
else: # 加速,否则让l查找到n会超时
l = mid
break
print(l)