[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] ...
随机推荐
- Java 设计模式实战系列—单例模式
本文首发公众号:小码A梦 单例模式是设计模式中最简单一个设计模式,该模式属于创建型模式,它提供了一种创建实例的最佳方式. 单例模式的定义也比较简单:一个类只能允许创建一个对象或者实例,那么这个类就是单 ...
- QA|外部调用类方法总报错missing 1 required positional argument:'self'|UI自动化
外部调用类方法总报错missing 1 required positional argument:'self' 原因:实例化这个类 实例化错了,少了括号() 解决:改成如下就可以了 参考学习:调用类方 ...
- Windows 某些软件显示"口口"解决办法
和乱码不同,文字变成"口口",一般是语言环境出错了. 解决办法 开始->控制面板->区域 (时钟.语言和区域)->区域:更改设置->管理->非 Uni ...
- 使用RabbitMQ最终一致性库存解锁
一.基本介绍 ①延时队列(实现定时任务) 场景:比如未付款订单,超过一定时间后,系统自动取消订单并释放占有物品. 常用解决方案: spring的 schedule定时任务轮询数据库:缺点:消耗系统内存 ...
- Jenkins持续集成入门到精通(进阶篇)
视频参考:https://www.bilibili.com/video/BV1Vp4y1b7ZN?p=51 1. Jenkins+Docker+SpringCloud持续集成流程说明 大致流程说明: ...
- 各快 100 倍?4G、5G、6G 相差这么多吗
二狗子今天晚上有点 emo,为什么呢? 原来是二狗子心心念很久的一个手游上线了,二狗子兴冲冲地下载了 40 多分钟,终于下载完了游戏.结果打开游戏一看,发现游戏内部的更新写着预计 30 分钟完成更新. ...
- Dubbo3应用开发——架构的演变过程
Dubbo3应用开发--架构的演变过程 什么是Dubbo 早期Dubbo的定位: 基于Java的高性能,轻量级的RPC框架:SOA[Service-Oriented Architecture ⾯向服务 ...
- 关于.Net 6.0 在Linux ,Docker容器中,不安装任何依赖就生成图形验证码!!!!!!!!!!!
在.Net Framework时代,我们生成验证码大多都是用System.Drawing. 在.Net 6中使用也是没有问题的. 但是,System.Drawing却依赖于Windows GDI+. ...
- 【c#版本Openfeign】Net8 自带OpenFeign实现远程接口调用
引言 相信巨硬,我们便一直硬.Net版本到现在已经出了7了,8也已经在预览版了,相信在一个半月就会正式发布,其中也有很多拭目以待的新功能了,不仅仅有Apm和Tap的结合,TaskToAscynResu ...
- MySql 数据 管理表的操作
管理表的操作 use scoredb; -- 查看数据库中有哪些表 show tables; show tables from bipowernode; -- 查看数据表的基础结构 show colu ...