Codeforces 1131 B. Draw!-暴力 (Codeforces Round #541 (Div. 2))
2 seconds
256 megabytes
standard input
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.
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.
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.
3
2 0
3 1
3 4
2
3
0 0
0 0
0 0
1
1
5 4
5
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.
题意就是按时间顺序给你比赛的比分,让你算有几次平局。
代码:
//B
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+; int main()
{
ll n;
cin>>n;
ll ans=,a=,b=;
for(int i=;i<n;i++){
ll x,y;
cin>>x>>y;
if(x==a&&y==b) continue;
if(a>b){
if(x>y){if(y>=a) ans+=y-a+;}
else ans+=x-a+;
}
else if(a<b){
if(x<y){if(x>=b) ans+=x-b+;}
else ans+=y-b+;
}
else if(a==b){
ans+=min(x,y)-a;
}
a=x,b=y;
}
cout<<ans<<endl;
}
Codeforces 1131 B. Draw!-暴力 (Codeforces Round #541 (Div. 2))的更多相关文章
- Codeforces Round #541 (Div. 2)
Codeforces Round #541 (Div. 2) http://codeforces.com/contest/1131 A #include<bits/stdc++.h> us ...
- Codeforces Round #541 (Div. 2) (A~F)
目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...
- Codeforces Round #541 (Div. 2) B.Draw!
链接:https://codeforces.com/contest/1131/problem/B 题意: 给n次足球比分,求存在平局的机会. 思路: 结构体存储,unique后,判断是否有分数交叉. ...
- Codeforces 1131 F. Asya And Kittens-双向链表(模拟或者STL list)+并查集(或者STL list的splice()函数)-对不起,我太菜了。。。 (Codeforces Round #541 (Div. 2))
F. Asya And Kittens time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 1131 C. Birthday-暴力 (Codeforces Round #541 (Div. 2))
C. Birthday time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces 1131 A. Sea Battle-暴力 (Codeforces Round #541 (Div. 2))
A. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #541 (Div. 2)题解
不知道该更些什么 随便写点东西吧 https://codeforces.com/contest/1131 ABC 太热了不写了 D 把相等的用并查集缩在一起 如果$ x<y$则从$ x$往$y$ ...
- Codeforces Round #541 (Div. 2) D(并查集+拓扑排序) F (并查集)
D. Gourmet choice 链接:http://codeforces.com/contest/1131/problem/D 思路: = 的情况我们用并查集把他们扔到一个集合,然后根据 > ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
随机推荐
- 增强学习Reinforcement Learning经典算法梳理3:TD方法
转自:http://blog.csdn.net/songrotek/article/details/51382759 博客地址:http://blog.csdn.net/songrotek/artic ...
- 与http协作的web服务器、http首部(第五章、第六章)
第五章 与http协作的web服务器 1.用单台虚拟主机实现多个域名 通过域名访问主机,经过DNS解析成ip地址,反向代理,可以代理多台服务器,正向代理则相反,代理客户端 2.通信数据转化程序:代理. ...
- quick-cocos2dx lua中读取 加密 csv表
我非常想把一些非必需的信息以CSV表的格式保存到客户端,以减少和服务器的通讯,降低压力.于是写了这么一个. 但因为大家觉得这样的话,需要每次登陆时来检测同步这些数据,会减慢登陆速度,于是没有用到. 我 ...
- mouseover/mouseenter/mouseout/mouseleave的区别
mouseover:鼠标指针穿过被选元素或其子元素,均会触发事件 mouseenter:鼠标指针穿过被选元素时才触发事件 mouseout:鼠标指针离开被选元素或其子元素则触发事件 mouseleav ...
- linux命令行todo列表管理工具Taskwarrior介绍
Taskwarrior 是一款在命令行下使用的TODO列表管理工具,或者说任务管理工具,灵活,快速,高效. 安装 在ubuntu 14.04 中,可从官方仓库安装task软件包 sudo apt-ge ...
- VPS L2TP配置
原文地址:https://raymii.org/s/tutorials/IPSEC_L2TP_vpn_with_Ubuntu_14.04.html 只要保证ipsec verify没错,基本都可以成功 ...
- 【数位dp入门】【HDU2089】62
为了我的点歪的技能树…… 所以开始补一些sb的东西…… #include<bits/stdc++.h> typedef long long ll; using namespace std; ...
- 设计模式之笔记--适配器模式(Adapter)
适配器模式(Adapter) 定义 适配器模式(Adapter),将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以在一起工作. 适配器模式 ...
- 网站服务器压力Web性能测试(2):Webbench:最多模拟3万个并发连接数测试压力
1.Webbench最多可以模拟3万个并发连接数来测试服务器压力,可以设置压力测试时间和测试请求的成功率.安装Webbench命令: wget https://home.tiscali.cz/~cz2 ...
- Android SDK更新 Connection to http://dl-ssl.google.com refused
问题: Failed to fetch URL https://dl-ssl.google.com/android/repository/repository-6.xml, reason: Conne ...