Codeforces Round #541 (Div. 2) B.Draw!
链接:https://codeforces.com/contest/1131/problem/B
题意:
给n次足球比分,求存在平局的机会。
思路:
结构体存储,unique后,判断是否有分数交叉。
一方当前分数小的时候,下一次分数小于当前对方时不存在平局,
下一次分数介于对方当前分数和下次分数之间时根据下次分数和当前对方分数。
否则表示对方分数被完全包含,反之同理。
代码:
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAXN = 1e4 + 10;
struct Node
{
int _l, _r;
bool operator == (const Node & that){
return this->_l == that._l && this->_r == that._r;
}
}node[MAXN]; int main()
{
int n;
cin >> n;
node[1]._l = 0;
node[1]._r = 0;
for (int i = 2;i <= n + 1;i++)
cin >> node[i]._l >> node[i]._r;
int res = 1;
int x = unique(node + 1,node + n + 2) - (node + 1);
for (int i = 1;i < x;i++)
{
if (node[i]._l == node[i]._r)
res += min(node[i + 1]._l, node[i + 1]._r) - node[i]._l;
else if (node[i]._l < node[i]._r)
{
if (node[i + 1]._l < node[i]._r)
continue;
if (node[i + 1]._l <= node[i + 1]._r)
res += node[i + 1]._l - node[i]._r + 1;
else
res += node[i + 1]._r - node[i]._r + 1;
}
else if (node[i]._l > node[i]._r)
{
if (node[i + 1]._r < node[i]._l)
continue;
if (node[i + 1]._r <= node[i + 1]._l)
res += node[i + 1]._r - node[i]._l + 1;
else
res += node[i + 1]._l - node[i]._l + 1;
}
}
cout << res << endl; return 0;
}
/*
3
1 1
2 2
3 3
*/
Codeforces Round #541 (Div. 2) B.Draw!的更多相关文章
- 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 1131 B. Draw!-暴力 (Codeforces Round #541 (Div. 2))
B. Draw! time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- 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 ...
- Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质
https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...
- Codeforces Round #541 (Div. 2) D 并查集 + 拓扑排序
https://codeforces.com/contest/1131/problem/D 题意 给你一个n*m二维偏序表,代表x[i]和y[j]的大小关系,根据表构造大小分别为n,m的x[],y[] ...
- Codeforces Round #541 (Div. 2) C.Birthday
链接:https://codeforces.com/contest/1131/problem/C 题意: 求给的n个数,相邻差值最小的排列方式.1-n相邻. 思路: sort后隔一个取一个,取到底后再 ...
随机推荐
- CSS3学习笔记(2)—左右跳动的红心
还在为无法表达内心澎湃的心情而着急吗?还在为制作跳动的心而烦恼吗?哈哈,今天我就把代码全部奉上,为你们追妹子添点贡献,下面来看最终的动态效果(事先说明一下:我用的截屏gif制作软件是绿色版的,所以gi ...
- RobotFramework教程使用笔记——时间控件的相关操作
在web测试过程中,我们可能会遇到时间控件,有的是支持直接输入的,有的为了保证输入时间格式的一致性是只支持点击选择的,那么这个时候如何用robotframework来操作呢? 看下面这个例子: 这个是 ...
- 网络测试常用的命令-比较ping,tracert和pathping等命令之间的关系
无论你是一个网络维护人员,还是正在学习TCP/IP协议,了解和掌握一些常用的网络测试命令将会有助于您更快地检测到网络故障所在,同时也会有助你您了解网络通信的内幕. 下面我们逐步介绍几个常用的命令: 1 ...
- Ansible 动态获取主机列表
参考文献: http://www.linuxidc.com/Linux/2016-12/138111.htm 附加 这个 include_vars 变量,可以 动态分别环境或者其他条件- hosts: ...
- PHP Json函数不能处理中文的解决办法
PHP5.2 新增的 json 功能是非常受欢迎的,但是经过测试发现,json_encode 对中文的处理是有问题的: 不能处理GB编码,所有的GB编码都会替换成空字符: utf8编码的中文被编码成u ...
- android BLE Peripheral 手机模拟设备发出BLE广播 BluetoothLeAdvertiser
android 从4.3系统开始可以连接BLE设备,这个大家都知道了.iOS是从7.0版本开始支持BLE. android 进入5.0时代时,开放了一个新功能,手机可以模拟设备发出BLE广播, 这个新 ...
- 关于S50卡密钥A和密钥B
关于S50卡密钥A和密钥B 1. Mifare_Std 卡片的密钥属性取决于控制字.控制字的默认值是“FF078069”,此时 A密钥:不可被读出,有全部权限. B密钥:可被读出,没有任何权限. 2. ...
- codeforces 665B B. Shopping(水题)
题目链接: B. Shopping time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Notepad++安装xml插件
环境: win7 64位 Notepad++7.3.3 原生的Notepad++不自带xml文件的插件,所以在显示xml文件时并不分行(如下图所示),对于用户编辑,查看的操作而言,并不友好,所以需要安 ...
- Logcat不显示Application的解决办法
Window - show view - devices - debug ----2014.12.1------ 只有在DDMS的device中显示进程名,logcat中的Application标签才 ...