跳到正文

题解

题解:P12279 [蓝桥杯 2024 国 Python A] 限流器

volatile约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年4月24日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 1 分钟
获赞
3
题目
P12279

版本

  1. v1当前

思路

用桶数组保存每个区间的请求次数即可,如何求一个时间戳是哪一个区间呢?因为每个区间是 [k⋅N,(k+1)⋅N)[k\cdot{N},(k+1)\cdot{N}),所以直接用这个时间戳整除 NN 即可求出每一个 kk。

代码

Python
n,m,l=map(int,input().split())
t=list(map(int,input().split()))
cnt={}
for i in t:
    if i//n in cnt:
        cnt[i//n]+=1
    else:
        cnt[i//n]=1
sum=0
for i in cnt.values():
    if i<=m:
        sum+=i
    else:
        sum+=m
print(sum)

cnt={'key1':'value1','key2':'value2'...} 说明 cntcnt 是一个字典,可以理解为 C++ 中的 map。

原文