[ABC261A] Intersection
Problem Statement
We have a number line. Takahashi painted some parts of this line, as follows:
- First, he painted the part from $X=L_1$ to $X=R_1$ red.
- Next, he painted the part from $X=L_2$ to $X=R_2$ blue.
Find the length of the part of the line painted both red and blue.
Constraints
- $0\leq L_1<R_1\leq 100$
- $0\leq L_2<R_2\leq 100$
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
$L_1$ $R_1$ $L_2$ $R_2$
Output
Print the length of the part of the line painted both red and blue, as an integer.
Sample Input 1
0 3 1 5
Sample Output 1
2
The part from $X=0$ to $X=3$ is painted red, and the part from $X=1$ to $X=5$ is painted blue.
Thus, the part from $X=1$ to $X=3$ is painted both red and blue, and its length is $2$.
Sample Input 2
0 1 4 5
Sample Output 2
0
No part is painted both red and blue.
Sample Input 3
0 3 3 7
Sample Output 3
0
其实求出来的区间就是 \([\max(L_1,L_2),\min(R_1,R_2)]\)
特判区间为空,输出区间长度。
#include<bits/stdc++.h>
using namespace std;
int l1,r1,l2,r2;
int main()
{
scanf("%d%d",&l1,&r1);
scanf("%d%d",&l2,&r2);
if(max(l1,l2)>min(r1,r2))
printf("0");
else
printf("%d",min(r1,r2)-max(l1,l2));
}
[ABC261A] Intersection的更多相关文章
- [LeetCode] Intersection of Two Arrays II 两个数组相交之二
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- [LeetCode] Intersection of Two Arrays 两个数组相交
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- [LeetCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- 【leetcode】Intersection of Two Linked Lists
题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...
- [LintCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...
- LeetCode Intersection of Two Arrays
原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays/ 题目: Given two arrays, write a func ...
- Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- LeetCode Intersection of Two Arrays II
原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays-ii/ 题目: Given two arrays, write a f ...
- LeetCode 350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- LeetCode 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
随机推荐
- 详解 canal 同步 MySQL 增量数据到 ES
canal 是阿里知名的开源项目,主要用途是基于 MySQL 数据库增量日志解析,提供增量数据订阅和消费. 这篇文章,我们手把手向同学们展示使用 canal 将 MySQL 增量数据同步到 ES . ...
- mybatis数据库字段自动填充
背景描述 目前,大多数项目的数据库设计,都会添加一些公共字段,比如version(版本号).deleted(逻辑删除标识).create_time.update_time.create_by.upda ...
- 使用vscodep快速编写markdown
写在前面 这是一篇基于 vscode 配置,用于书写 markdown 的文章 为了方便快速书写 markdown 真想使用一些便捷的快捷键去生成一些自己常用的格式或者是模版,于是自己基于自己的个人习 ...
- 「codeforces - 185D」Visit of the Great
link. 简单提一下做法,注意到 \(k^{2^a}\equiv k^{2^b}\equiv-1\equiv (-1)^{2^{b-a}}=1\pmod{(k^{2^a}+1,k^{2^{b}}+1 ...
- Solution -「CF 1477A」Nezzar and Board
Description Link. $ n $ distinct integers $ x_1,x_2,\ldots,x_n $ are written on the board. Nezzar ca ...
- 其它——MySQL主从搭建基于docker
文章目录 10分钟搭建MySQL主从同步(基于docker) 一 主从配置原理 二 操作步骤 2.1我们准备两台装好mysql的服务器(我在此用docker模拟了两台机器) 2.2 远程连接入主库和从 ...
- rte-rtc
活动内容 个人中心 立即报名 活动详情 RTE大会(原"RTC大会")创立于2015年,是亚太首个.迄今为止规模最大的实时互联网技术盛会,覆盖200+行业场景 ...
- Error in v-on handler: “TypeError: _user.default is not a function“
碰到这个问题一开始以为是方法名重复了,后来检查了一遍也没发现方法名或者属性名重复然后发现是 这个导入方法时没加{}的问题. , 无语.
- 重温dp——最长上升公共子序列
一道经典的dp了 题目描述 给出 1,2,-,n 的两个排列 P1 和 P2 ,求它们的最长公共子序列. 输入格式 第一行是一个数 n. 接下来两行,每行为 n 个数,为自然数 1,2,-,n 的一 ...
- AI图形算法之一:液位计识别
AI人工智能的主要应用之一就是图形化处理和识别,之前写了两篇,分别是: AI图形算法的应用之一:通过图片模板对比发现油田漏油 AI图形算法的应用之一:仪表识别 经过几个晚上的辛苦,液位计识别也测试成功 ...