zoukankan      html  css  js  c++  java
  • B

    You still have partial information about the score during the historic football match. You are given a set of pairs (ai,bi)(ai,bi), indicating that at some point during the match the score was "aiai: bibi". It is known that if the current score is «xx:yy», then after the goal it will change to "x+1x+1:yy" or "xx:y+1y+1". What is the largest number of times a draw could appear on the scoreboard?

    The pairs "aiai:bibi" are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match.

    Input

    The first line contains a single integer nn (1n100001≤n≤10000) — the number of known moments in the match.

    Each of the next nn lines contains integers aiai and bibi (0ai,bi1090≤ai,bi≤109), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team).

    All moments are given in chronological order, that is, sequences xixi and yjyj are non-decreasing. The last score denotes the final result of the match.

    Output

    Print the maximum number of moments of time, during which the score was a draw. The starting moment of the match (with a score 0:0) is also counted.

    Examples

    Input
    3
    2 0
    3 1
    3 4
    Output
    2
    Input
    3
    0 0
    0 0
    0 0
    Output
    1
    Input
    1
    5 4
    Output
    5

    Note

    In the example one of the possible score sequences leading to the maximum number of draws is as follows: 0:0, 1:0, 2:0, 2:1, 3:1, 3:2, 3:3, 3:4.

     1 #include <iostream>
     2 #include <cstdio>
     3 
     4 using namespace std;
     5 
     6 const int max_N = 1e4+10;
     7 
     8 int a,b;
     9 int n;
    10 
    11 int main()
    12 {
    13     scanf("%d",&n);
    14     int min_num=0,max_num=0,ans=1,before_a=0,before_b=0;
    15     
    16     // 注意(x,x)的特殊情况判断
    17 
    18     for(int i=0;i<n;++i)
    19     {
    20         scanf("%d %d",&a,&b);
    21         min_num=min(a,b);
    22         if(min_num>=max_num)
    23         {
    24             ans+=1 + min_num - max_num;
    25         }
    26 
    27         if(before_a==before_b)
    28         {
    29             --ans;
    30         }
    31 
    32         before_a=a,before_b=b;
    33 
    34         max_num=max(a,b);
    35     }
    36     printf("%d",ans);
    37     return 0;
    38 }
  • 相关阅读:
    详解C#break ,continue, return
    c# winform 全角自动转化半角问题(C#中ImeMode的值):转载
    简短总结一下C#里跨线程更新UI(转)
    必备:常用px,pt,em换算表(转)
    C# Textbox的ImeMode取值对中文输入法的影响 (转)
    转自:C#中TextBox水印提示的简单实现
    转载:C# this.invoke()作用 多线程操作UI 理解二
    转载:C# this.Invoke()的作用与用法 理解三
    MySQL数据库----基础操作
    python之路----线程
  • 原文地址:https://www.cnblogs.com/jishuren/p/12239587.html
Copyright © 2011-2022 走看看