B - Draw!
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.
Examples
3
2 0
3 1
3 4
2
3
0 0
0 0
0 0
1
1
5 4
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.
#include <iostream>
#include <cstdio> using namespace std; const int max_N = 1e4+; int a,b;
int n; int main()
{
scanf("%d",&n);
int min_num=,max_num=,ans=,before_a=,before_b=; // 注意(x,x)的特殊情况判断 for(int i=;i<n;++i)
{
scanf("%d %d",&a,&b);
min_num=min(a,b);
if(min_num>=max_num)
{
ans+= + min_num - max_num;
} if(before_a==before_b)
{
--ans;
} before_a=a,before_b=b; max_num=max(a,b);
}
printf("%d",ans);
return ;
}
B - Draw!的更多相关文章
- 深入浅出聊优化:从Draw Calls到GC
前言: 刚开始写这篇文章的时候选了一个很土的题目...<Unity3D优化全解析>.因为这是一篇临时起意才写的文章,而且陈述的都是既有的事实,因而给自己“文(dou)学(bi)”加工留下的 ...
- Direct3D Draw函数 异步调用原理解析
概述 在D3D10中,一个基本的渲染流程可分为以下步骤: 清理帧缓存: 执行若干次的绘制: 通过Device API创建所需Buffer: 通过Map/Unmap填充数据到Buffer中: 将Buff ...
- Unity性能优化之 Draw Call原理<转>
Unity(或者说基本所有图形引擎)生成一帧画面的处理过程大致可以这样简化描述:引擎首先经过简单的可见性测试,确定摄像机可以看到的物体,然后把这些物体的顶点(包括本地位置.法线.UV等),索引(顶点如 ...
- Cocos2d 利用继承Draw方法制作可显示三维数据(宠物三维等)的三角形显示面板
很久没有写博客了,这段时间比较忙,又是搬家又是做自己的项目,还有太多琐碎的事情缠身,好不容易抽出时间把最近自己做的一些简单例子记录一下. 在我的项目中,我需要一个显示面板来显示游戏中的一个三维数据,例 ...
- OpenCascade Draw Test Harness
OpenCascade Draw Test Harness eryar@163.com Abstract. Draw is a command interpreter based on Tcl/Tk ...
- 移动端上传照片 预览+Draw on Canvas's Demo(解决 iOS 等设备照片旋转 90 度的 bug)
背景: 本人的一个移动端H5项目,需求如下: 需求一:手机相册选取或拍摄照片后在页面上预览 需求二:然后绘制在canvas画布上 这里,我们先看一个demo(http://jsfiddle.net/q ...
- Android UI 绘制过程浅析(四)draw过程
前言 draw是绘制View三个步骤中的最后一步.同measure.layout一样,通常不对draw本身进行重写,draw内部会调用onDraw方法,子类View需要重写onDraw(Canvas) ...
- 优化 从Draw Calls到GC
原文出处: 慕容小匹夫的博客(@慕容小匹夫) 欢迎分享原创到伯乐头条 前言: 刚开始写这篇文章的时候选了一个很土的题目...<Unity3D优化全解析>.因为这是一篇临时起意才写的文章 ...
- VC++ 在使用 CImage 的Draw 输入一个图像时,有时候会造成图像失真严重,解决的方法如下
VC++ 在使用 CImage 的Draw 输入一个图像时,有时候会造成图像失真严重,解决的方法如下 失真主要是由于变形造成的.只要设置一下变形的模式就可以了 ::SetStretchBltMode ...
- Method Draw – 很好用的 SVG 在线编辑器
Method Draw 是一款在线 SVG 编辑器,是 SVG Edit 的一个分支.Method Draw 的目的是改进 SVG Edit 的可用性和用户体验.它移除了 line-caps/corn ...
随机推荐
- [terminal]终端仿真程序
char * szCommAry[COMM_NUM]={ //屏幕属性命令,23 "\x1b[12h",//禁止本端回显,键盘数据仅送给主机 "\x1b[12l" ...
- ARTS Week 8
Dec 16, 2019 ~ Dec 22, 2019 Algorithm Problem 53 Maximum Subarray 最大子数组 题目链接 题目描述:给定一个数组,在所有连续的子数组中, ...
- (二)Mybatis动态sql
首先动态sql简单来讲就是可以根据传入参数的不同来动态的生成sql语句,拼接where语句,这样你就不用写很多个sql语句了,并且它里面有一些特性也可以帮助你避免sql语句的拼接错误,主要分为4个: ...
- 08-SpringMVC02
今日知识 1. 文件上传 2. ResponseBody和RequestBody 3. SpringMVC多视图 4. 静态资源的处理 文件上传 1. 导包,(commom.io , commons- ...
- php 安装 event 和 libevent 扩展
这里使用的是php7.0.24 ,php是yum安装的 一.安装event扩展 用yum无法安装event扩展 手动安装 php 必须要开启 sockets 功能,需要安装php的socket扩展,才 ...
- H5谷歌登录 webview错误
接入谷歌登录 H5接入谷歌登录打包apk使用webview谷歌登录不上(谷歌不支持用户代理被归类为嵌入式用户代理(也称为网络视图),因此不允许向Google发出OAuth授权请求) 解决办法:替换ua ...
- 一次压力测试Bug排查-epoll使用避坑指南
Bug复现 使用Webbench对服务器进行压力测试,创建1000个客户端,并发访问服务器10s,正常情况下有接近8万个HTTP请求访问服务器. 结果显示仅有7个请求被成功处理,0个请求处理失败,服务 ...
- Arm开发板+Qt学习之路-multiple definition of
问题描述:在一个头文件a.h中定义一些变量x,在其他.c文件中(b.c,c.c)要用到.用一般的全局变量的方法,编译时总是提示error:multiple definition of x 问题分析:o ...
- java的异常体系 及强制转换
一,异常 1.常见的几种异常: StackOverFlow 栈溢出错误:写递归函数的时候,没有定义递归结束的条件. ArrayIndexOutofBounds 数组越界:如新new一个数组,in ...
- Git push时不需要总输入密码
遇到问题: 最近因为换了自己的邮箱密码后,每次push的时候都需要填写密码,账号.很烦 解决方法: [戎马半生的答案] (http://www.cnblogs.com/zhaoyu1995/p/650 ...