• cf-750C (New Year and Rating) (思维,区间)


    https://codeforces.com/problemset/problem/750/C

    题意:

    oj比赛按等级分为A组和B组。等级<=1899,只能参加B组,等级>=1900,只能参加A组。求,在不知道某人初始等级的情况下,计算这个人参加比赛前的最高分数是多少?

    第一行输入n

    接下来n行,每行输入两个整数c,d,分别是,分数变化量和第几组。

    无线大输出 Infinity,不可能出现比赛情况Impossible,否则输出结果。

    思路:

    可以根据初始的分数确定可能的区间,区间最右边就是最大值,每次参加A组比赛时,更新区间的最左边。

    在最差条件下,必须在参加这次A组比赛前参加一场比赛,才由B组升级到1900,得到区间的左端点。

    而每次参加B组的比赛时更新右边界,在最优情况下,必须在参加B组比赛前,参加一场A组才能降到1899,得到区间右端点。

    最后输出结果即可。

    代码:

    #include<iostream>
    #include<stdio.h>
    #include<stdlib.h>
    #include<string>
    #include<iomanip>
    #include<algorithm>
    #include<string.h>
    #include<queue>
    #include<cmath>
    #include<stack>
    
    using namespace std;
    const int maxn=1e5+10;
    const int inf=0x7f7f7f7f;
    typedef long long ll;
    
    int n;
    
    int main()
    {
        int c,d;
        cin>>n;
        int ans=0;
        int l=-inf,r=inf;
        int x=0;
        for(int i=0; i<n; i++)
        {
            cin>>c>>d;
            if(d==1)  l=max(1900-x,l);
            else r=min(1899-x,r);
            x+=c;
        }
        if(l>r) cout<<"Impossible"<<endl;
        else if(r==inf) cout<<"Infinity"<<endl;
        else cout<<r+x<<endl;
       // system("pause");
        return 0;
    }
  • 相关阅读:
    shell读取文件不改变文本格式
    lua 的 os.date os.time
    gerrit 操作
    docker 的 镜像生成系列
    Windows 跟 Linux 文件共享:Samba 设置
    viscode 使用 格式的配置
    python pip 升级 或者换源
    centos 的系统管理命令 service systemctl
    Linux 的 netstat 命令
    MVC 、MTV 模式
  • 原文地址:https://www.cnblogs.com/sweetlittlebaby/p/14355468.html
Copyright © 2020-2023  润新知