题目描述: 游泳池,一个进水管和一个排水管,开始开关都是打开状态,分别每度过t1, t2 时间改变开关的状态,开关打开时分别每分钟排入,排出 m1,m2 的水量。 当进水管和排水管同时打开时,游泳池水量变化为每分钟m1-m2,游泳池的水量不能为负数,最大容量为m,水量不能超过m。计算 t 时刻泳池的水量。 输入: 5 有几组数 10 2 1 5 2 5 每一组数 10 2 10 5 2 5 10 2 3 5 2 5 100 100 3 4 4 3 1000 1000 10 5 5 3 输出: 0 10 2 3 2495
python实现:
exps=int(input())
list1=[]
for i in range(exps):
list1.append(list(map(int,input().split())))
for i in range(exps):
result=0
m,t,m1,t1,m2,t2=list1[i][0],list1[i][1],list1[i][2],list1[i][3],list1[i][4],list1[i][5]
for j in range(1,t+1):#j表示每分钟,直到t分钟后
if j%(2*t1)<=t1 and j%(2*t1)>0:#当t在t1到2t1之间时,进水管进水m1
result+=m1
if j%(2*t2)<=t2 and j%(2*t2)>0:#t在t2到2t2之间时,排水管出水m2
result-=m2
if result<=0:
result=0
elif result>=m:
result=m
print(result)