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. AI绘画StableDiffusion实操教程:可爱头像奶茶小女孩(附高清图片)

    本教程收集于:AIGC从入门到精通教程汇总 今天继续分享AI绘画实操教程,如何用lora包生成超可爱头像奶茶小女孩 放大高清图已放到教程包内,需要的可以自取. 欢迎来到我们这篇特别的文章--<A ...

  2. 在 Spring 6 中使用虚拟线程

    一.简介 在这个简短的教程中,我们将了解如何在 Spring Boot 应用程序中利用虚拟线程的强大功能. 虚拟线程是Java 19 的预览功能,这意味着它们将在未来 12 个月内包含在官方 JDK ...

  3. Vim深入使用指南

    Vim深入使用指南 Vim是一款功能强大的文本编辑器,被广泛用于编写和编辑各种类型的文档和代码. 安装Vim 可以操作系统下载并安装Vim.在安装完成后,通过在终端中输入vim命令来启动Vim. Vi ...

  4. 推荐vue脚手架工具 vue-cli

    安装vue-cli之前,需要先装好vue 和 webpack npm install -g vue //全局安装vue npm install -g webpack //全局安装webpack npm ...

  5. 在同一个k8s集群中部署多套nginx-controller

    1.nginx-controller部署请参考我的另一篇博客 nginx Ingress Controller Packaged by Bitnami 2.修改values.yaml 不通contro ...

  6. C++类内存分布+ Studio工具

    书上类继承相关章节到这里就结束了,这里不妨说下C++内存分布结构,我们来看看编译器是怎么处理类成员内存分布的,特别是在继承.虚函数存在的情况下. 工欲善其事,必先利其器,我们先用好Visual Stu ...

  7. Python正则表达式——常用re正则表达式集合

    文章目录 一.校验数字的表达式 二.校验字符的表达式 三.特殊需求表达式 一.校验数字的表达式 数字:^[0-9]*$ n位的数字:^\d{n}$ 至少n位的数字:^\d{n,}$ m-n位的数字:^ ...

  8. Python基础——垃圾回收、格式化输入输出、基本运算符、流程控制

    文章目录 每日测验 垃圾回收机制详解(了解) 引用计数 标记清除 分代回收 与用户交互 接收用户的输入 字符串的格式化输出 填充与格式化 基本运算符 算数运算符 比较运算符: >.>=.& ...

  9. [AHOI2002] Kitty猫基因突变

    我们不妨将所有权值打到一棵树上,这很容易想到. 考虑暴力,如果我们选择了 \(w\) 个点,修改后我们会从叶子节点依次合并去计算贡献. 很显然我们可以动态规划维护. \(f[p][w][0/1/2]\ ...

  10. JavaScript 语法:语法约定与程序调试

    作者:WangMin 格言:努力做好自己喜欢的每一件事 JavaScript 语法约定 1.大小写的区分 1). JavaScript的关键字,永远都是小写的: 2). 内置对象,如Math和Date ...