zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    迭代器&可迭代对象
    递归&栈帧空间
    locals()和globals()
    闭包
    nonlocal和global
    LEGB
    python中编码问题
    关于dict的formkeys方法注意
    深浅拷贝
    通过远程连接批量查看zookeeper服务状态和判断主从节点
  • 原文地址:https://www.cnblogs.com/sweetlittlebaby/p/14355468.html
Copyright © 2011-2022 走看看