Codeforces 1131 B. Draw!-暴力 (Codeforces Round #541 (Div. 2))

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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
Copy
3
2 0
3 1
3 4
output
Copy
2
input
Copy
3
0 0
0 0
0 0
output
Copy
1
input
Copy
1
5 4
output
Copy
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 //B
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 typedef long long ll;
 5 const int maxn=1e5+10;
 6 
 7 int main()
 8 {
 9     ll n;
10     cin>>n;
11     ll ans=1,a=0,b=0;
12     for(int i=0;i<n;i++){
13         ll x,y;
14         cin>>x>>y;
15         if(x==a&&y==b) continue;
16         if(a>b){
17             if(x>y){if(y>=a) ans+=y-a+1;}
18             else ans+=x-a+1;
19         }
20         else if(a<b){
21             if(x<y){if(x>=b) ans+=x-b+1;}
22             else ans+=y-b+1;
23         }
24         else if(a==b){
25             ans+=min(x,y)-a;
26         }
27         a=x,b=y;
28     }
29     cout<<ans<<endl;
30 }

 

 

 

转载于:https://www.cnblogs.com/ZERO-/p/10426426.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值