[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] ...
随机推荐
- 分布式存储系统举例剖析(elasticsearch,kafka,redis-cluster)
1. 概述 对于分布式系统,人们首先对现实中的分布式系统进行高层抽象,然后做出各种假设,发展了诸如CAP, FLP 等理论,提出了很多一致性模型,Paxos 是其中最璀璨的明珠.我们对分布式系统的时序 ...
- 循环神经网络RNN完全解析:从基础理论到PyTorch实战
在本文中,我们深入探讨了循环神经网络(RNN)及其高级变体,包括长短时记忆网络(LSTM).门控循环单元(GRU)和双向循环神经网络(Bi-RNN).文章详细介绍了RNN的基本概念.工作原理和应用场景 ...
- QA|重写了元素定位后报错xx object has no attribute 'find_element'|网页计算器自动化测试实战
代码如下: 1 # basepage.py 2 3 from selenium import webdriver 4 5 6 class BasePage(): 7 """ ...
- Vue源码学习(四):<templete>渲染第三步,将ast语法树转换为渲染函数
好家伙, Vue源码学习(三):<templete>渲染第二步,创建ast语法树, 在上一篇,我们已经成功将 我们的模板 转换为ast语法树 接下来我们继续进行操作 1.方法封装 由于 ...
- 小知识:调整OCI实例的时区
之前在随笔中<Linux (RHEL)修改时区> 介绍了时区修改方法. 默认OCI实例中,时区是GMT,在国内用看着这个时区就是很别扭的事情,于是修改时区,实测无需配置 /etc/sysc ...
- python入门基础(13)--类、对象
面向过程的编程语言,如C语言,所使用的数据和函数之间是没有任何直接联系的,它们之间是通过函数调用提供参数的形式将数据传入函数进行处理. 但可能因为错误的传递参数.错误地修改了数据而导致程序出错,甚至是 ...
- 解密TCP连接断开:四次挥手的奥秘和数据传输的安全
TCP 连接断开 在当今数字化时代,互联网已经成为了人们生活中不可或缺的一部分.而在互联网的基础之上,TCP协议扮演着关键的角色,它负责着数据在网络中的可靠传输.在TCP连接的建立过程中,我们已经了解 ...
- Python使用socket的UDP协议实现FTP文件服务
简介 本示例主要是用Python的socket,使用UDP协议实现一个FTP服务端.FTP客户端,用来实现文件的传输.在公司内网下,可以不适用U盘的情况下,纯粹使用网络,来实现文件服务器的搭建,进而实 ...
- flask出现This is a development server. Do not use it in a production deployment. Falsk WSGI两种解决办法
WARNING: This is a development server. Do not use it in a production deployment. Falsk WSGI "这个 ...
- ElasticSearch系列——倒排索引、删除映射类型、打分机制、配置文件、常见错误
文章目录 1 倒排索引 2 删除映射类型 一 前言 二 什么是映射类型? 三 为什么要删除映射类型? 四 映射类型的替代方法 4.1 将映射类型分开存储在索引中 4.2 自定义类型字段回到顶部 五 没 ...