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的更多相关文章

  1. [LeetCode] Intersection of Two Arrays II 两个数组相交之二

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  2. [LeetCode] Intersection of Two Arrays 两个数组相交

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

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

  4. 【leetcode】Intersection of Two Linked Lists

    题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...

  5. [LintCode] Intersection of Two Linked Lists 求两个链表的交点

    Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...

  6. LeetCode Intersection of Two Arrays

    原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays/ 题目: Given two arrays, write a func ...

  7. Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  8. LeetCode Intersection of Two Arrays II

    原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays-ii/ 题目: Given two arrays, write a f ...

  9. LeetCode 350. Intersection of Two Arrays II

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  10. LeetCode 349. Intersection of Two Arrays

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

随机推荐

  1. [语音识别] 基于Python构建简易的音频录制与语音识别应用

    语音识别技术的快速发展为实现更多智能化应用提供了无限可能.本文旨在介绍一个基于Python实现的简易音频录制与语音识别应用.文章简要介绍相关技术的应用,重点放在音频录制方面,而语音识别则关注于调用相关 ...

  2. 使用 docker 打包构建部署 Vue 项目,一劳永逸解决node-sass安装问题

    文章源于 Jenkins 构建 Vue 项目失败,然后就把 node_modules 删了重新构建发现 node-sass 安装不上了,折腾一天终于可以稳定构建了. 犹记得从学 node 的第一天,就 ...

  3. React Native实现Toast轻提示和loading

    React Native 封装Toast 前言 使用react native的小伙伴都知道,官方并未提供轻提示组件,只提供了ToastAndroid API,顾名思义,只能再安卓环境下使用,对于ios ...

  4. git命令和遇到的问题

    命令 1.快速关联/修改Git远程仓库地址 (1).删除本地仓库当前关联的无效远程地址,再为本地仓库添加新的远程仓库地址 git remote -v //查看git对应的远程仓库地址 git remo ...

  5. Solution -「THUPC 2019」Duckchess

    Description Link. 大模拟是不可能给你概括题意的. Solution (据说鸭棋题解用这个标题很吉利)(这里是被点名批评的 长度 19k 的打法)(先说好代码里 Chinglish 满 ...

  6. TCP连接的关键之谜:揭秘三次握手的必要性

    TCP 连接建立 当我们浏览网页.发送电子邮件或者进行在线游戏时,我们常常不会想到背后复杂的网络连接过程.然而,正是这些看似不起眼的步骤,确保了我们与服务器之间的稳定通信.其中最重要的步骤之一就是TC ...

  7. 浅谈TCP协议的发生过程

    1. TCP协议 1.1 TCP协议的性质 面向连接的.可靠的.基于字节流 至于为什么面向连接,又为什么可靠,基于字节流的,等后面便可知道. 1.2 TCP协议栈收发数据的四个阶段 创建套接字 连接服 ...

  8. Langchain-Chatchat项目:1-整体介绍

      基于Langchain与ChatGLM等语言模型的本地知识库问答应用实现.项目中默认LLM模型改为THUDM/chatglm2-6b[2],默认Embedding模型改为moka-ai/m3e-b ...

  9. Windows下音视频对讲演示程序(声学回音消除、噪音抑制、语音活动检测、自动增益控制、自适应抖动缓冲)(2023年07月13日更新)

    Windows下音视频对讲演示程序 必读说明 简介   本软件根据<道德经>为核心思想而设计,实现了两个设备之间进行音视频对讲,一般可用于楼宇对讲.智能门铃对讲.企业员工对讲.智能对讲机. ...

  10. 「CSP-2023」我曾璀璨星空,星月相伴,致远方,致过往。

    Day -1   像往常一样去上学.虽然身在学校但感觉心还在比赛上.在一个上午课间准备去上厕所时遇见了信息老师.她在教我们班信息之前我的一些奖状的指导教师就是写的她,之前就认识了,每次碰到她都会朝我笑 ...