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 }
  • 相关阅读:
    【ROM修改教程】添加高级电源重启菜单(安卓4.0.4官方ROM)
    MTK 快速开机 技术详解
    MT6592 经验积累
    Android系统之Broadcom GPS 移植
    Android关机流程源码分析
    Android 4.1.2系统添加重启功能
    android4.2添加重启菜单项
    MTK平台 Android4.0.3 定制关机动画
    不进化,则消亡——互联网时代企业管理的十项实践
    前端切图:调用百度地图API
  • 原文地址:https://www.cnblogs.com/jishuren/p/12239587.html
Copyright © 2011-2022 走看看