CodeForces - 750C(思维)

本文介绍了一个关于Codeforces比赛分数变化的问题解决方法。通过对输入数据的分析,确定参赛者等级变化前后可能的最大分数,并通过代码实现了解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:


题意:Codeforces里分两个等级,分数在1900及其以上是dev1,在1899及其以下是dev2,分数可以是负的。给出最近几场比赛的数据,求可能的最大分数。给出n对数据c和d。d是指在在参加这场比赛之前的等级,c是指这场比赛结束后变化的分数。


题解:经过思考过后你会发现,最后一个c是无所谓的,因为它没给出变化后的等级。所以我们将数据错一分开,如:

c  d     这样以后数据就成了给出这场比赛结束后的分数变化和等级。

   1     例中的就是先给出当前等级1,一场比赛结束后负了7分,等级变成了2。

-7  2     维护已经出现的数据的最小值和最大值,等级1有最小可能1900,等级2有最大可能1899。记录总分

5  5     数变化,只管当前数据的最值。只要比赛结束后是等级1,则比赛前最小分数就是1900 - c。只要比

8        赛结束后是等级2,则比赛前最小分数就是1899 - c。最后通过最值的关系得出结果。


#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main()
{
    int n, c, d, cut = 0, mins = -INF, maxs = INF;
    scanf("%d", &n);
    while(n--){
        scanf("%d%d", &c, &d);
        if(d == 1) mins = max(mins, 1900 - cut);    //比赛结束后是dev1,则之前最小值为1900-c
        else maxs = min(maxs, 1899 - cut);          //比赛结束后是dev2,则之前最小值为1899-c
        cut += c;                                   //将数据错位开了
    }
    
    //注意记录的是全过程的最值。
    //每次比赛结束后的最值分数要么是1900要么就是1899,因为比赛结束后是dev1,最小就是1900,同理1899。
    //可我们记录的是当前比赛之前的最值。
    
    if(mins > maxs) puts("Impossible");
    else if(maxs == INF) puts("Infinity");
    else printf("%d\n", maxs + cut);

    return 0;
}


### Codeforces Problem 976C Solution in Python For solving problem 976C on Codeforces using Python, efficiency becomes a critical factor due to strict time limits aimed at distinguishing between efficient and less efficient solutions[^1]. Given these constraints, it is advisable to focus on optimizing algorithms and choosing appropriate data structures. The provided code snippet offers insight into handling string manipulation problems efficiently by customizing comparison logic for sorting elements based on specific criteria[^2]. However, for addressing problem 976C specifically, which involves determining the winner ('A' or 'B') based on frequency counts within given inputs, one can adapt similar principles of optimization but tailored towards counting occurrences directly as shown below: ```python from collections import Counter def determine_winner(): for _ in range(int(input())): count_map = Counter(input().strip()) result = "A" if count_map['A'] > count_map['B'] else "B" print(result) determine_winner() ``` This approach leverages `Counter` from Python’s built-in `collections` module to quickly tally up instances of 'A' versus 'B'. By iterating over multiple test cases through a loop defined by user input, this method ensures that comparisons are made accurately while maintaining performance standards required under tight computational resources[^3]. To further enhance execution speed when working with Python, consider submitting codes via platforms like PyPy instead of traditional interpreters whenever possible since they offer better runtime efficiencies especially important during competitive programming contests where milliseconds matter significantly.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值