[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] ...
随机推荐
- 如何在kubernetes中实现分布式可扩展的WebSocket服务架构
如何在kubernetes中实现分布式可扩展的WebSocket服务架构 How to implement a distributed and auto-scalable WebSocket serv ...
- 15种实时uv实现方案系列(附源码)之一:Flink基于set实时uv统计
UVStatMultiPlans(GitHub)项目持续收集各种高性能实时uv实现方案并对各种实现方案的优缺点进行对比分析! 需求描述 统计每分钟用户每个页面的uv访问量. Kafka数据格式 {&q ...
- Solution -「洛谷 P7395」「CoE-I 2021C」弹珠游戏
Description Link. 游戏在 \(4\times4\) 的菱形棋盘上进行: 两名玩家轮流放置弹珠,可以在横向.纵向.\(45\) 度斜线.\(135\) 度斜线方向未放置弹珠的位置连续放 ...
- ORACEL12C ORA-01033:ORACLE 正在初始化或关闭
问题:客户端报ORA-01033 原因:oracle12C CDB启动,但是可拔插的PDB实例未启动 解决办法: sqlplus / as sysdba--系统管理员登录 alter session ...
- Blazor前后端框架Known-V1.2.16
V1.2.16 Known是基于C#和Blazor开发的前后端分离快速开发框架,开箱即用,跨平台,一处代码,多处运行. Gitee: https://gitee.com/known/Known Git ...
- Python socket实现简单聊天,同步输入和接收消息
查的资料很多都是必须等待接收数据后才能再次输入.做了修改,使用多线程的形式,实现一边输入,一边接收 服务端代码 import socket import threading import sys im ...
- Windows下VC++编译器32位memcpy、memmove函数汇编代码详解
整理者:赤勇玄心行天道 QQ号:280604597 微信号:qq280604597 QQ群:511046632 博客:www.cnblogs.com/gaoyaguo blog.csdn.net/c ...
- 从零用VitePress搭建博客教程(1) – VitePress的安装和运行
1.从零用VitePress搭建博客说明(1) – VitePress的安装和运行 一.写在前面 最近在想更新一把自己的前端吧小博客,但发现wordPress版本停留在了5年之前,发现变化挺大,不支持 ...
- kubeadm 工具部署 kubernetes v1.16.2
环境准备 3个节点,以下基于 Centos 7.6 系统, 内核版本:3.10.0-957.12.2.e17.x86_64 HOST NODE CPU MEM 192.168.1.111 master ...
- Python 利用pandas 和 matplotlib绘制柱状图
当你需要展示数据时,图表是一个非常有用的工具.Python 中的 pandas 和 matplotlib 库提供了丰富的功能,可以帮助你轻松地绘制各种类型的图表.本文将介绍如何使用这两个库,绘制一个店 ...