跳到正文

题解

题解:P16298 [蓝桥杯 2026 省 Python C 组] 解题速度对决

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

文章信息

发布
2026年4月13日
收录
2026年6月13日
更新
2026年11月16日
篇幅
约 1 分钟
题目
P16298

版本

  1. v1当前

哎不行了只能继续用 Python 了

1.题目解析

小蓝:每道题耗时 t1t1 分钟,做完第 ii 题后休息 i×d1i \times d1 分钟(最后一题后不休息)。

小红:每道题耗时 t2t2 分钟,做完第 ii 题后休息 i×d2i \times d2 分钟。

两人同时开始,求谁先完成。

小蓝总时间

做题总时间: n×t1n \times t1

休息总时间: d1×(1+2+...+(n−1))=d1×n×(n−1)÷2d1 \times (1 + 2 + ... + (n-1)) = d1 \times n \times (n-1) \div 2

所以:

Python
blue=n*t1+d1*n*(n-1)//2

小红总时间

同理:

Python
red=n*t2+d2*n*(n-1)//2

比较规则

如果 blue<red 输出 BLUE
如果 blue>red 输出 RED
否则 输出 DRAW

时间复杂度

时间复杂度 O(T)O(T) ,非常快

2.代码

Python
T=int(input())
for _ in range(T):
    n,t1,d1,t2,d2=map(int, input().split())
    blue=n*t1+d1*n*(n-1)//2
    red=n*t2+d2*n*(n-1)//2
    if blue<red:
        print("BLUE")
    elif blue>red:
        print("RED")
    else:
        print("DRAW")
原文