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 }
复制代码

 

 

 

posted @   ZERO-  阅读(547)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
历史上的今天:
2018-02-24 POJ 3368.Frequent values-处理数据+RMQ(ST)
点击右上角即可分享
微信分享提示