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;
}

 

posted on 2021-02-01 10:48  mmn  阅读(78)  评论(0编辑  收藏  举报