Draw!

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

 

Description

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 (1≤n≤100001≤n≤10000) — the number of known moments in the match.

Each of the next nn lines contains integers aiai and bibi (0≤ai,bi≤1090≤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.

Sample Input

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

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.

题意:

两个人进行比赛,给出几场两人的比分,问在满足这几场比分的条件下,最多会出现几场平局(开始的0:0也算一场)。

解题思路:

将比赛双方看成两条不断前进的线段,利用区间的方式去模拟比赛的情况。

重点是Debug,在思路找不到错误的情况下,就去多试一些样例,尽量的做到测试的不重不漏。

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
const double e=exp();
const int N = ; queue<LL> check;
int main()
{
LL i,p,j,n,t;
LL ans = ;
LL a1,b1,a2,b2; while(!check.empty())
check.pop(); scanf("%lld",&n);
scanf("%lld%lld",&a1,&b1); ans += min(a1, b1) + ;
check.push(min(a1,b1));
for(i = ; i < n; i ++)
{
scanf("%lld%lld",&a2,&b2);
if(a2 < b1 || a1 > b2)
;
else if(a1 < b1 && a2 <= b2 && a2 >= b1)
{
ans+=(a2 - b1) + ; if(check.front() == b1)
{
ans--; }
check.pop();
check.push(a2);
}
else if(a1 >= b1 && a2 <= b2)
{
ans+=(a2 - a1 + ); if(check.front() == a1)
{
ans--; }
check.pop();
check.push(a2);
}
else if(a1 >= b1 && a1 <= b2 && a2 > b2)
{
ans += b2 - a1 + ; if(check.front() == a1)
{
ans--; }
check.pop();
check.push(b2);
}
else if(a1 <= b1 && a2 >= b2)
{
ans += b2 - b1 + ; if(check.front() == b1)
{
ans--; }
check.pop();
check.push(b2);
}
a1 = a2;
b1 = b2;
}
printf("%lld\n",ans);
return ;
}

CF 1131B Draw!的更多相关文章

  1. CF 1131A,1131B,1131C,1131D,1131F(Round541 A,B,C,D,F)题解

    A. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. CF 553A 组合DP

    http://codeforces.com/problemset/problem/553/A A. Kyoya and Colored Balls time limit per test 2 seco ...

  3. 【打CF,学算法——三星级】Codeforces Round #313 (Div. 2) C. Gerald&#39;s Hexagon

    [CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/C 题面: C. Gerald's Hexagon time limit per tes ...

  4. CF泛做

    CF Rd478 Div2 A Aramic script 题意:给定几个字符串,去重后,求种类 思路:直接map乱搞 #include<bits/stdc++.h> using name ...

  5. 【codeforces】【比赛题解】#937 CF Round #467 (Div. 2)

    没有参加,但是之后几天打了哦,第三场AK的CF比赛. CF大扫荡计划正在稳步进行. [A]Olympiad 题意: 给\(n\)个人颁奖,要满足: 至少有一个人拿奖. 如果得分为\(x\)的有奖,那么 ...

  6. CF练习记录

    2018/5/6 Codeforces Round #478 (Div. 2) C http://codeforces.com/contest/975/problem/C Valhalla Siege ...

  7. 深入浅出聊优化:从Draw Calls到GC

    前言: 刚开始写这篇文章的时候选了一个很土的题目...<Unity3D优化全解析>.因为这是一篇临时起意才写的文章,而且陈述的都是既有的事实,因而给自己“文(dou)学(bi)”加工留下的 ...

  8. Direct3D Draw函数 异步调用原理解析

    概述 在D3D10中,一个基本的渲染流程可分为以下步骤: 清理帧缓存: 执行若干次的绘制: 通过Device API创建所需Buffer: 通过Map/Unmap填充数据到Buffer中: 将Buff ...

  9. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

随机推荐

  1. PHP完美分页类

    <?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 private $lis ...

  2. process.tar.gz

    exec1.c #include <stdio.h> #include <unistd.h> int main() { char *arglist[3]; arglist[0] ...

  3. 个人作业3——个人总结AlPha阶段

    一.Alpha版本的总结 1.感受 Alpha版本已经结束了,回顾整个过程,我最大的遗憾就是项目完成得不是很理想,同时觉得自己做得不够多.不够好. 2.我做了哪些工作 数据库的连接,部分团队博客:部分 ...

  4. 团队作业(五)——旅游行业的手机App

    首先是作业要求: 在PM 带领下, 每个团队深入分析下面行业的App, 找到行业的Top 5 (从下面的三个备选中,任选一个行业即可) 英语学习/词典App 笔记App 旅游行业的手机App 我们选择 ...

  5. jQuery笔记(二)

    $()下的常用方法 addClass():添加样式 removeClass():删除样式 $('div').addClass('box2 box4'); $('div').removeClass('b ...

  6. [Delphi]实现使用TIdHttp控件向https地址Post请求[转]

    开篇:公司之前一直使用http协议进行交互(比如登录等功能),但是经常被爆安全性不高,所以准备改用https协议.百度了一下资料,其实使用IdHttp控件实现https交互的帖子并不少,鉴于这次成功实 ...

  7. Jmeter使用笔记之组件的作用域

    以前一直使用loadrunner,最近入职新公司后需要使用jmeter,这里把使用过程中出现的一些问题进行总结,同时会和自己使用loadrunner的情况相比较,以后也会不断总结,GO! 一.组件的作 ...

  8. Docker(九)-Docker创建Selenium容器

    SeleniumHQ官方项目:https://github.com/seleniumHQ/docker-selenium 项目目前快速迭代中. Selenium 这里主要针对的是 Selenium G ...

  9. 三星a9上测试egret与pixi.js的渲染性能

    for (let i = 0; i < 500; i++) { let shape = new egret.Shape(); shape.graphics.beginFill(0xff0000) ...

  10. PostgreSQL之oracle_fdw安装与使用

    目的介绍 现在项目开发遇到一个问题,就是需要从PostgreSQL中访问Oracle数据库 身为渣渣猿一脸懵逼.于是乎请教了公司的数据库方面的大牛韩工.告诉我用oracle_fdw 可以实现,但是在实 ...