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后隔一个取一个,取到底后再 ...
随机推荐
- [CPP - STL] functor刨根问底儿
作为STL六大组件之一,在STL源代码及其应用中,很多地方使用了仿函数(functor),尤其在关联型容器(如set.map)以及algorithm(如find_if.count_if等)中.虽然已经 ...
- Java线程面试题 Top 50(转载)
原文链接:http://www.importnew.com/12773.html 本文由 ImportNew - 李 广 翻译自 javarevisited 不管你是新程序员还是老手,你一定在面试中遇 ...
- Linux 修改所属组与所属人
1.chown work /test/* 修改test文件夹下所有文件的所属人(owner)为work 2.chgrp work /test/* 修改test文件夹下所有文件的所属组(group)为w ...
- hdu-5726 GCD(rmq)
题目链接: GCD Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Prob ...
- Linux 命令行 Tricks
区分文件和目录: ls -F ls -F -R:递归显示目录 仅改变文件的修改时间,而不修改文件的内容: touch filename: 使用 file 命令查看文件类型: ASCII text di ...
- Apktool 和 Jeb 给出的不同的smali语法
今天发现用Apktool和Jeb反编译出来的smali在语法上有一定区别,比如一个Java函数: private void packageNameCheck() { com.example.testf ...
- C# 获取点击列的索引
datagridview 怎么获取选中行的某一列的索引比如 下面是表学号 姓名 所在年级 1 张 高一 2 李 高二当我选择第二行的时候 我想取所在年级的列索引 这时候那个 ...
- linux drwxr-xr-x 什么意思
第一位表示文件类型. d:是目录文件, l:是链接文件, -:是普通文件, p:是管道 第2-4位表示这个文件的属主拥有的权限,r是读,w是写,x是执行.(其中r是4,w是2,x是1) 第5-7位表示 ...
- 【Data structure & Algorithm】把二元查找树转变成排序的双向链表
把二元查找树转变成排序的双向链表 题目:输入一棵二元查找树,将该二元查找树转换成一个排序的双向链表,要求不能创建任何新节点,只调整指针指向. 比如将二元查找树 10 / \ 6 ...
- 技术胖Flutter第四季-20导航的参数传递和接受-1
技术胖Flutter第四季-20导航的参数传递和接受-1 视频地址:https://www.bilibili.com/video/av35800108/?p=21 先安装一个新的插件: Awesome ...