A. Meeting of Old Friends
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!

Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya.

Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive.

Calculate the number of minutes they will be able to spend together.

Input

The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.

Output

Print one integer — the number of minutes Sonya and Filya will be able to spend together.

Examples
Input
1 10 9 20 1
Output
2
Input
1 100 50 200 75
Output
50
Note

In the first sample, they will be together during minutes 9 and 10.

In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.

题目链接:http://codeforces.com/problemset/problem/714/A

解题思路:

【题意】

Sonya每天只有[l1,r1]时间段内空闲,且在k时刻,她要打扮而不能够见Filya

Filya每天[l2,r2]时间段内空闲

问他们俩每天有多少时间能够在一起

【类型】
区间交

【分析】

显然,要求他们俩每天有多少时间在一起

其实就是求两区间的交集

那无外乎就是对两区间的位置关系进行分析

,。当然还有几个图这里就不一一列举了,主要就是找到两个的

相交区间,然后判断k是否在这个区间中,在的话减一;

这道题要用long long,否则会超!

下面给出AC代码:

 #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
ll l1,l2,r1,r2,k;
while(cin>>l1>>r1>>l2>>r2>>k)
{
ll minn = min(r1,r2);
ll maxn = max(l1,l2);
ll ans = minn-maxn+;
if(maxn > minn)
{
cout<<<<endl;
continue;
}
if(k >= maxn && k <= minn)
ans--;
cout<<ans<<endl;
}
return ;
}

Codeforces 714A Meeting of Old Friends的更多相关文章

  1. Codeforces 714A 朋友聚会

    参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6395268.html A. Meeting of Old Friends time limit p ...

  2. CodeForces 714A

    Description Today an outstanding event is going to happen in the forest — hedgehog Filya will come t ...

  3. CodeForces 144B Meeting

    暴力. 题目只要求计算边上的点就可以了,一开始没看清题意,把内部的也算进去了.内部的计算可以延迟标记一下,但这题没有必要. #include<map> #include<set> ...

  4. CodeForces A. Meeting of Old Friends

    2019-05-30 20:19:57 加油!!! sort(a + 1, a + 5); 卡了一会儿 #include <bits/stdc++.h> using namespace s ...

  5. CSUST 8.5 早训

    ## Problem A A - Meeting of Old Friends CodeForces - 714A 题意: 解题说明:此题其实是求两段区间的交集,注意要去除掉交集中的某个点. 题解: ...

  6. 2018SDIBT_国庆个人第六场

    A - A codeforces 714A Description Today an outstanding event is going to happen in the forest — hedg ...

  7. codeforces 782B The Meeting Place Cannot Be Changed (三分)

    The Meeting Place Cannot Be Changed Problem Description The main road in Bytecity is a straight line ...

  8. Codeforces Round #375 (Div. 2) A. The New Year: Meeting Friends 水题

    A. The New Year: Meeting Friends 题目连接: http://codeforces.com/contest/723/problem/A Description There ...

  9. Codeforces Round #371 (Div. 2) A. Meeting of Old Friends 水题

    A. Meeting of Old Friends 题目连接: http://codeforces.com/contest/714/problem/A Description Today an out ...

随机推荐

  1. HTTP服务及状态码

    第一章 HTTP 1.1 HTTP协议的概念 HTTP协议,全称HyperText Transfer Protocol,中文名为超文本传输协议,是互联网上常用的通信协议之一,它有很多的应用.但是流行的 ...

  2. 数据库的SQL优化

    1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. (因为在条件查询条件添加索引,会直接被检索到列,会非常的快速) 2.应尽量避免在 wher ...

  3. C:数据结构与算法之顺序表

    顺序表作为数据结构的开端,说明这里面很多基础要学,初学者一开始都会混淆,今天我们来一步一步来建立一个完整的顺序表,可以任我们控制的顺序表,首先先定义一个顺序表 /* Note:Your choice ...

  4. linux权限设置(开放某个文件夹给指定用户)

    问题背景: 今天想把自己的数据集开放给同事a,只允许其读,不允许写. 操作: step1: 查看该文件夹属于哪一个用户,哪一个组 ls 文件夹 -lstep2: usermod -a -G 指定文件夹 ...

  5. ES6 let和const命令(2)

    为什么要使用块级作用域 在ES5中只有全局作用域和函数作用域,没有块级作用域,因此带来了这些麻烦 内层变量可能会覆盖外层变量 var tmp = new Date(); console.log(tmp ...

  6. Create 命令详解

    mkdir:创建一个目录 /mkdir a b c :创建同级目录 /mkdir -p aa/bb/cc: 递归创建目录touch:修改文件时间戳,或者新建一个不存在的文件 /-a 更改存取时间 /m ...

  7. FPGA浮点数定点化

    因为在普通的fpga芯片里面,寄存器只可以表示无符号型,不可以表示小数,所以在计算比较精确的数值时,就需要做一些处理,不过在altera在Arria 10 中增加了硬核浮点DSP模块,这样更加适合硬件 ...

  8. js控制图片自动缩放,实现铺满盒子,不变形,完全局中

    此js一般用于控制图片铺满盒子,但是比例不变,并且绝对局中原理:判断图片的高宽与盒子高宽的大小的关系,然后通过比例来控制图片的缩放及定位<!DOCTYPE html PUBLIC "- ...

  9. mysql 错误信息

    1 连接MySQL错误:Can't connect to MySQL server (10060) link:>>>  http://blog.csdn.net/testcs_dn/ ...

  10. TypeScript VS JavaScript 深度对比

    TypeScript 和 JavaScript 是目前项目开发中较为流行的两种脚本语言,我们已经熟知 TypeScript 是 JavaScript 的一个超集,但是 TypeScript 与 Jav ...