日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【思维】draw!

發布時間:2025/3/8 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【思维】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

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.

題目大意:先輸入一個整數n,再接著輸入n組數代表比賽過程中的比分,求在存在要求的比分下最多能有多少場平局,注:0:0也算一場平局。

解決方法:由第一次給出的比分可確定在此之前的平局總數最大為ans=min(x,y)+1,此后從第二次開始到結束,設當前比分為x:y,前一次比分為lx:ly,由此可判斷,若x<ly||y<ly,則證明這兩次之間無平局出現,若lx=ly,則平局數為ans+=min(x-lx,y-ly),若lx>ly,則ans+=min(x,y)-lx+1,若lx<ly,則ans+=min(x,y)-ly+1。

AC代碼:

#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <map> #include <stack> #include <queue> #include <vector> #include <bitset> #include <set> #include <utility> #include <sstream> #include <iomanip> using namespace std; typedef long long ll; typedef unsigned long long ull; #define inf 0x3f3f3f3f #define rep(i,l,r) for(int i=l;i<=r;i++) #define lep(i,l,r) for(int i=l;i>=r;i--) #define ms(arr) memset(arr,0,sizeof(arr)) //priority_queue<int,vector<int> ,greater<int> >q; const int maxn = (int)1e5 + 5; const ll mod = 1e9+7; int main() {#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);int n;cin>>n;int ans=1;int x,y,lx,ly;cin>>x>>y;ans+=min(x,y);lx=x;ly=y;rep(i,2,n) {cin>>x>>y;if(x<ly||y<lx) {lx=x;ly=y;continue;}if(lx==ly) ans+=min(x-lx,y-ly);else if(lx>ly) {if(x>=y) ans+=y-lx+1;else ans+=x-lx+1;}else {if(y>=x) ans+=x-ly+1;else ans+=y-ly+1;}lx=x;ly=y;}cout<<ans<<endl;return 0; }

?

總結

以上是生活随笔為你收集整理的【思维】draw!的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久操影视 | 欧美a级片在线观看 | 日本特级毛片 | 色吊丝av中文字幕 | 亚洲高清毛片 | 91pron在线 | 97人人模人人爽人人少妇 | 国产一区亚洲一区 | 色999视频| 亚洲不卡中文字幕无码 | 已满十八岁免费观看全集动漫 | 日韩欧美视频一区二区三区 | 四虎影裤| 嫩草精品 | 91中文 | 第一章豪妇荡乳黄淑珍 | 亚洲av无码一区二区乱子伦 | 精品久久久久久久免费人妻 | 日韩丰满少妇 | 国产精品suv一区二区69 | 在线观看亚洲精品视频 | 日韩一区二区三区精品视频 | 大胸美女啪啪 | 国产熟女一区二区 | 免费的一级黄色片 | 国产视频精品久久 | 久久99精品久久久久婷婷 | 欧美性大战久久久久久久 | 国产精品夜夜爽张柏芝 | 国产无套精品一区二区 | 96精品在线 | 美少妇av | a视频在线| 青青草综合视频 | 欧美绿帽交换xxx | 亚洲精品国产片 | 黄色大片免费观看 | 久久天天综合 | 亚洲中文字幕视频一区 | 开心激情播播 | 91看片淫黄大片 | 国产亚洲欧美在线视频 | 国产精品色 | 日日草日日干 | 国产一区二区在线播放视频 | 国产精品一级黄色片 | 红桃成人在线 | 精品国产一区二区三区日日嗨 | 亚洲熟乱 | 男女在线视频 | 日韩av在线一区 | 日韩视频一区在线 | 久久久久99人妻一区二区三区 | 蜜乳av一区 | 黄色一极视频 | 久久久久久不卡 | 顶级黄色片| 男人的天堂狠狠干 | 久久精品欧美一区二区三区不卡 | 国产激情无套内精对白视频 | 日本寂寞少妇 | 久久久久亚洲av无码专区喷水 | 五月婷婷综 | 国产午夜精品一区二区三区欧美 | 久久精品99国产精 | 伊人久久五月天 | 午夜影院黄 | 先锋av网| 欧美精品1 | 午夜写真片福利电影网 | 激情免费视频 | 欧美日韩色综合 | 久久久国际精品 | 一区二区三区四区中文字幕 | 成人免费毛片高清视频 | 在线中文字日产幕 | 国产色呦呦 | 亚洲精品一区二区在线 | 老司机精品在线 | 天堂一区二区三区四区 | 国产在线网站 | 一级福利片 | 日本东京热一区二区三区 | 国语播放老妇呻吟对白 | 黄视频在线 | 激情第一页 | 青青草手机视频 | 国产日韩欧美在线观看 | 成人在线免费小视频 | 国产无码精品合集 | 福利电影一区二区三区 | 免费在线你懂的 | 人妻丰满熟妇aⅴ无码 | 壮汉被书生c到合不拢腿 | 激情小视频 | 韩日精品中文字幕 | 在线www色| 久久爱影视| 精品乱码一区二区三四区视频 |