CodeForces 1131B Draw!

F - Draw!

https://codeforces.com/problemset/problem/1131/B

Description

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

The pairs “ai:bi” 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 n (1≤n≤10000) — the number of known moments in the match.

Each of the next n lines contains integers ai and bi (0≤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 xi and yj are non-decreasing. The last score denotes the final result of

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.

Sample Input

3
2 0
3 1
3 4
3
0 0
0 0
0 0
1
5 4

Sample Output

2
1
5

Hint

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.

题意

水题一道,输入在某个时刻的两队球队的得分,问相同的分数的时刻至多会有多少个。

#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,x,y;
	int sum1=0,sum2=0,ans=1;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d%d",&x,&y);
		if(sum1==x&&sum2==y) continue;
		else {
			if(sum1==sum2) {
				ans+=(min(x,y)-sum1);
			}
			else {//假设min(x,y)是x,x一定大于sum1,
				int sum=(min(x,y)-max(sum1,sum2)+1);//但x不一定大于sum2,
				if(sum>0) ans+=sum;//因此判断一下sum的值

			}
			sum1=x;
			sum2=y;
		}
	}
	printf("%d\n",ans);
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值