zoukankan      html  css  js  c++  java
  • Codefroces 750C:New Year and Rating(思维)

    C. New Year and Rating
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.

    Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division di (i.e. he belonged to this division just before the start of this contest) and his rating changed by ci just after the contest. Note that negative ci denotes the loss of rating.

    What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".

    Input

    The first line of the input contains a single integer n (1 ≤ n ≤ 200 000).

    The i-th of next n lines contains two integers ci and di ( - 100 ≤ ci ≤ 100, 1 ≤ di ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.

    Output

    If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the ncontests.

    Examples
    input
    3
    -7 1
    5 2
    8 2
    output
    1907
    input
    2
    57 1
    22 2
    output
    Impossible
    input
    1
    -5 1
    output
    Infinity
    input
    4
    27 2
    13 1
    -50 1
    8 2
    output
    1897
    Note

    In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating:

    • Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7.
    • With rating 1894 Limak is in the division 2. His rating increases by 5.
    • Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets  + 8 and ends the year with rating 1907.

    In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.

     思路:设立一个上下限l=-inf, r=inf.然后根据从c[i] d[i] 和 c[i]的累计值s来不断更新l r;最后判断若r小于f则 “Impossible” ,若上界未改变则为“Infinity”。

     eg:若d[i]=2,则r=min(r,1899-s) .若d[i]=1,则l=max(l,1900-s);

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<queue>
     6 #define pi acos(-1.0)
     7 #define mj
     8 #define inf 2e8+500
     9 typedef  long long  ll;
    10 using namespace std;
    11 const int N=2e5+5;
    12 int c[N],d[N];
    13 int main()
    14 {
    15     int n;
    16     scanf("%d",&n);
    17     int l=-inf,r=inf;
    18     int s=0;
    19     for(int i=0;i<n;i++){
    20         scanf("%d%d",&c[i],&d[i]);
    21         if(d[i]==1){
    22             l=max(l,1900-s);
    23         }
    24         else{
    25             r=min(r,1899-s);
    26         }
    27         s+=c[i];
    28     }
    29     if(r<l){
    30         printf("Impossible
    ");
    31     }
    32     else if(r==inf){
    33         printf("Infinity
    ");
    34     }
    35     else {
    36         printf("%d
    ",r+s);
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    关于lucene断点续索引和增量索引的问题
    发布一个关于统计时间段的MDX语句
    【蛙蛙推荐】想设计一个关于软件开发的元搜索引擎,希望大家支持
    python中and和or的用法
    Hadoop实战中高级部分 之 Hadoop MapReduce高级编程
    (转)对实时分析与离线分析的思考(二)
    数据分析站点导航
    MapReduce:详解Shuffle过程
    分析能力的8个等级(My Level)
    (转)Tire Tree
  • 原文地址:https://www.cnblogs.com/mj-liylho/p/6368849.html
Copyright © 2011-2022 走看看