链接: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. 使用php ffmpeg处理视频

    工作中遇到video加载视频的问题,但是视频封面在手机上无法取到视频的第一帧,video标签无法在手机上取到第一帧,经过几天的研究于搜索终于找到比较好用的办法,就是php ffmped 插件,该插件的 ...

  2. ubuntu动态加载模块简单模板

    1:简单代码 #include<linux/init.h> #include<linux/module.h> MODULE_LICENSE("GPL"); ...

  3. 【bzoj2286】[Sdoi2011]消耗战

    虚树入门题: #include<cstdio> #include<cstring> #include<algorithm> #include<ctime> ...

  4. 基于Appium、Python的自动化测试

    基于Appium.Python的自动化测试环境部署和实践   第一章 导言 1.1 编制目的 该文档为选用Appium作为移动设备原生(Native).混合(Hybrid).移动Web(Mobile ...

  5. DIY固件系列教程——实现开机LOGO三屏动画的完全替换【转】

    本文转载自:http://blog.csdn.net/sdgaojian/article/details/9192433 本教程需要用到如下工具:1,7Z压缩工具2,AddCrc32效验工具3,raw ...

  6. led子系统【转】

    本文转载自:http://blog.csdn.net/yuanlulu/article/details/6438841 版权声明:本文为博主原创文章,未经博主允许不得转载. ============= ...

  7. HDU3605 Escape —— 二分图多重匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 4000/2000 MS (Java/Others)    ...

  8. TCP/IP,HTTP,Socket初识

    在大学时候学过网络通信这一块,奈何已经还给老师,苍天饶过谁,该拾起来看看学学的还是要学,先简单了解了下这方面的知识,后续会继续通过看书来充实这方面的知识. 手机能够联网是手机底层实现了TCP/IP协议 ...

  9. 用mingw-w64 编译 x64 位的ffmpeg

    http://blog.sina.com.cn/s/blog_6125d067010168dt.html 工作中用到了ffmpeg x64. 发现编译出来x64的ffmpeg,很不容易.特记录下来.原 ...

  10. mysql的navicat注册码生成

    首先下载安装Navicat在Navicat关闭的情况下运行注册机在注册机界面点击patch,选择Navicat安装目录下的Navicat.exe打补丁弹出破解成功后拔掉网线断网products选择my ...