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. 使用API接口获取淘宝商品数据的详细指南

    ​ 在电商行业中,淘宝作为中国最大的在线购物平台,每天有数以百万计的商品被发布和交易.作为程序员,如果需要获取淘宝商品的详细数据,可以通过调用API接口来实现.本文将详细介绍如何使用淘宝API接口获取 ...

  2. crontab定时任务不执行的一些原因总结

    参考博文地址: https://www.jb51.net/article/154290.htm声明:本文章是在以上地址博文基础上进行整理学习,如有侵权,请联系博主删除,感谢知识共享,一起进步,加油鸭 ...

  3. cpu分布式训练论文阅读

    Large Scale Distributed Deep Networks Downpour SGD: 模型的副本采用异步方式从参数服务器(Parameter Server)中获取参数w和上传Δw到参 ...

  4. 使用“文心一言”编写技术博文《搭建企业知识库:基于 Wiki.js 的实践指南》

    百度于8月31日零点宣布,文心一言率先向全社会全面开放.我也是立即体验了下,感觉还不错.下面分享一下,如何使用"文心一言"写一篇技术博客. Step 01 生成文案主体 可以对文心 ...

  5. utils工具类整理

    闲暇之余,整理出了项目中常用的一些工具类,不是很全,后续会持续更新--- 全部代码请移植github哦-github地址:https://github.com/yang302/utils

  6. SQL Server查询数据库中的表

    SQL Server查询数据库中的表 SSMS中用不了MySQL中的show 查询当前数据库中所有表名: SELECT name FROM sysobjects WHERE (xtype = 'U') ...

  7. Wood,微型 Java ORM 框架(首次发版)

    Wood,微型 Java ORM 框架(支持:java sql,xml sql,annotation sql:事务:缓存:监控:等...),零依赖! 特点和理念: 跨平台:可以嵌入到JVM脚本引擎(j ...

  8. 1-MySQL数据库的安装和基础语法介绍

    1.MySQL是什么? MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,属于 Oracle 旗下产品.它是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最 ...

  9. Go语言系列——21-Go协程、22-信道(channel)、23-缓冲信道和工作池、24-Select、25-Mutex、26-结构体取代类、27-组合取代继承、多态、 29-Defer、错误处理

    文章目录 21-Go协程 Go 协程是什么? Go 协程相比于线程的优势 如何启动一个 Go 协程? 启动多个 Go 协程 22-信道(channel) 什么是信道? 信道的声明 通过信道进行发送和接 ...

  10. Top 5 Code Smells Newbies Developers Could Easily Identify & Avoid

    Posted by Ajitesh Kumar / In Freshers, Software Quality / February 1, 2014 Following is one very pop ...