[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] ...
随机推荐
- SpringSecurity简明教程
SpringSecurity主要实现UserDetailsService来验证登录的用户信息,和Security的配置类来对登录方式和资源进行限制. 案例包含利用数据库进行登录验证.URL访问限制.自 ...
- nvm、node、vue安装、vue项目创建打包
nvm.node.vue安装.创建vue项目 nvm作用:可以管理多个版本的node,切换node版本,下载node. 前情提要 参 考:https://zhuanlan.zhihu.com/p/51 ...
- Vue源码学习(五):<templete>渲染第四步,生成虚拟dom并将其转换为真实dom
好家伙, 前情提要: 在上一篇我们已经成功将ast语法树转换为渲染函数 现在我们继续 1.项目目录 代码已开源https://github.com/Fattiger4399/analytic ...
- pci p2p
概述 在2018年,针对pci支持p2pdma的驱动合入主线,没记错的话应该是4.20. 补丁如下: commit 52916982af48d9f9fc01ad825259de1eb3a9b25e A ...
- Linux常用命令大全 Linux Commands Line - v1.0
The most complete and updated list of commands on linux by LinuxGuide.it - over 350 commands! ...
- Graph RAG: 知识图谱结合 LLM 的检索增强
本文为大家揭示 NebulaGraph 率先提出的 Graph RAG 方法,这种结合知识图谱.图数据库作为大模型结合私有知识系统的最新技术栈,是 LLM+ 系列的第三篇,加上之前的图上下文学习.Te ...
- JAVA图搜索算法之DFS-BFS
图算法DFS与BFS BFS和DFS代表对图进行遍历,即搜索的算法,搜索算法中常用的只要有两种算法:深度优先遍历(Depth-First-Search : DFS)和广度优先遍历(Breadth-Fi ...
- Skywalking APM监控系列(一丶.NET5.0+接入Skywalking监听)
前言 新项目采用的abp vnext的微服务模块化架构,所以把应用的服务拆成了很多独立模块 在初期,我们通过日志还能跟踪到问题, 后期服务越来越多(大约扩充到了十几个),随着调用链路越来越深 ,问题也 ...
- math库常用函数+产生随机数总结
math库常用函数+产生随机数总结 1.对x开平方 double sqrt(x)://返回值为double类型,输入的x类型随意,只要是数的类型 2.求常数e的x次方 double exp(x);// ...
- ELK7.x环境部署
1.Elasticsearch (ES)配置: 部署配置ES,需要配置JDK环境,JDK是Java语言的软件开发工具包: 下载JAVA jdk源码包: wget https://mirrors.yan ...