链接: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!的更多相关文章

  1. Codeforces Round #541 (Div. 2)

    Codeforces Round #541 (Div. 2) http://codeforces.com/contest/1131 A #include<bits/stdc++.h> us ...

  2. Codeforces Round #541 (Div. 2) (A~F)

    目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...

  3. 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 ...

  4. Codeforces Round #541 (Div. 2)题解

    不知道该更些什么 随便写点东西吧 https://codeforces.com/contest/1131 ABC 太热了不写了 D 把相等的用并查集缩在一起 如果$ x<y$则从$ x$往$y$ ...

  5. Codeforces Round #541 (Div. 2) D(并查集+拓扑排序) F (并查集)

    D. Gourmet choice 链接:http://codeforces.com/contest/1131/problem/D 思路: =  的情况我们用并查集把他们扔到一个集合,然后根据 > ...

  6. Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)

    https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...

  7. Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质

    https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...

  8. Codeforces Round #541 (Div. 2) D 并查集 + 拓扑排序

    https://codeforces.com/contest/1131/problem/D 题意 给你一个n*m二维偏序表,代表x[i]和y[j]的大小关系,根据表构造大小分别为n,m的x[],y[] ...

  9. Codeforces Round #541 (Div. 2) C.Birthday

    链接:https://codeforces.com/contest/1131/problem/C 题意: 求给的n个数,相邻差值最小的排列方式.1-n相邻. 思路: sort后隔一个取一个,取到底后再 ...

随机推荐

  1. linux vsftpd

    FTP是CS架构的.使用的是ftp协议. root@ubuntu:/# apt install vsftpd root@ubuntu:/# service vsftpd status ● vsftpd ...

  2. HDU4372 Count the Buildings —— 组合数 + 第一类斯特林数

    题目链接:https://vjudge.net/problem/HDU-4372 Count the Buildings Time Limit: 2000/1000 MS (Java/Others)  ...

  3. HackerRank leonardo-and-lucky-numbers —— 模线性方程的通解

    题目链接:https://vjudge.net/problem/HackerRank-leonardo-and-lucky-numbers 题解: 1.根据扩展欧几里得:7*x + 4*y = gcd ...

  4. socket技术与负载均衡

    网络编程 Nginx1.9之前使用 Lvs  Haproxy 实现四层反向和负载均衡 Lvs可以i应用到所有负载均衡的功能 数据库 web服务等 四层负载均衡,根据连接进行保存. 断开,连接.进行轮训 ...

  5. git rev-list 和 git rev-parse

    git-rev-list - Lists commit objects in reverse chronological order https://git-scm.com/docs/git-rev- ...

  6. (转)Java经典设计模式(1):五大创建型模式(附实例和详解)

    原文出处: 小宝鸽 一.概况 总体来说设计模式分为三大类: (1)创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. (2)结构型模式,共七种:适配器模式.装饰器模式.代 ...

  7. mysql批量sql插入优化

    对于一些数据量较大的系统,数据库面临的问题除了查询效率低下,还有就是数据入库时间长.特别像报表系统,每天花费在数据导入上的时间可能会长达几个小时或十几个小时之久.因此,优化数据库插入性能是很有意义的. ...

  8. Vue父子组件间的通信

    父组件通过 props 向下传递数据给子组件,子组件通过 events 向上给父组件发送消息. 父组件: <div> <div style="background:#344 ...

  9. python中的linspace,meshgrid,concatenate函数

    linspace可以用来实现相同间隔的采样. numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None) ...

  10. [TJOI 2018] XOR

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5338 [算法] 首先对这棵树进行树链剖分 那么我们就将一个树上的问题转化为一个序列上 ...