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后隔一个取一个,取到底后再 ...
随机推荐
- go 客户端服务端通信
client.go package main import ( "bufio" "encoding/json" "fmt" "ha ...
- 转载——Android permission 访问权限大全
程序执行需要读取到安全敏感项必需在androidmanifest.xml中声明相关权限请求, 完整列表如下: Android.permission.ACCESS_CHECKIN_PROPERTIES ...
- linux内核段属性机制【转】
本文转载自:https://github.com/TongxinV/oneBook/issues/9 linux内核段属性机制 以subsys_initcall和module_init为例 subsy ...
- 自动化测试框架selenium+java+TestNG——读取csv文件
读取csv文件可以直接读取,也可以使用javacsv.jar,后者比较简单,这个也可以变相认为是对表格的处理,我们可以在表格中做好数据,存储成csv格式的文件,后续对xlsx表格的操作抽个时间再记录下 ...
- spring mvc提交日期类型参数
如题,spring mvc直接提交Date类型参数会报错,400 bad request的错误.在controller里加上 @InitBinder protected void initBinder ...
- JSR 303 - Bean Validation 是什么?
关于 Bean Validation JSR 303 - Bean Validation 是jree6 中的一项子规范,JSR 303 - Bean Validation着重解决以下实际问题: 在任何 ...
- uglifyjs2全局混淆
从git克隆uglifyjs2源码后,进入目录: npm link 编译并安装uglifyjs2成功,就可以直接调用uglifyjs命令了.但是在进行全局混淆时出现了问题,虽然指定了文件topvar. ...
- CentOS环境 升级Python2.6.6至2.7.5
1.查看当前Python版本 # python -V Python 2.6.6 # python -V Python 2.6.6 2.下载Python2.7.5源码 # wget http://p ...
- Swift类和结构体
在C++中,相信不会有太多人去详细考究结构体和类的区别,因为二者关系实在不大.但在Swift中,结构体和类的关系非常大,它们的组成部分都包括:初始化器.实例方法.实例属性.类型属性.类型方法等等:二者 ...
- Batch Normalization层
Batch Normalization的加速作用体现在两个方面:一是归一化了每层和每维度的scale,所以可以整体使用一个较高的学习率,而不必像以前那样迁就小scale的维度:二是归一化后使得更多的权 ...