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. <大话设计模式>笔记

    读完了<大话设计模式>这本书,收获很多,对程序设计有了很多新的理解.将每章模式的大概要点做了些笔记以备查阅,一些设计模式书读完也对其了解得不是很透彻,需要以后在实践中来不断地加深理解吧.读 ...

  2. sourceTree git 忽略指定文件

    按照如下步骤执行(终端命令) 1. git status modified: LovegoMall.xcworkspace/xcuserdata/Tiny.xcuserdatad/xcdebugger ...

  3. XMPP协议的基本理解

    即时通讯技术简介 即时通讯技术(IM)支持用户在线实时交谈.如果要发送一条信息,用户需要打开一个小窗口,以便让用户及其朋友在其中输入信息并让交谈双方都看到交谈的内容.大多数常用的即时通讯发送程序都会提 ...

  4. FormData自定义上传图片

    由于前段时间的项目中 涉及到图纸的上传 前端大神很随意的扔给我一个页面 让我自己修修改改 找了好几个素材站都没有找到合适的上传插件 最后不得已 用formdata 写了一个 顺便记录下吧 html 代 ...

  5. Libevent源码分析 (1) hello-world

    Libevent源码分析 (1) hello-world ⑨月份接触了久闻大名的libevent,当时想读读源码,可是由于事情比较多一直没有时间,现在手头的东西基本告一段落了,我准备读读libeven ...

  6. 开发过程遇到的bug

    1.transition和display的冲突: 解决方法:1)使用visibility:2)使用js的setTimeout使动画延迟:3)可以改变高度: 2.form表单提交和js中的提交冲突 解决 ...

  7. [知了堂学习笔记]_用JS制作《飞机大作战》游戏_第2讲(四大界面之间的跳转与玩家飞机的移动)

    一.通过点击按钮事件,实现四大界面之间的跳转: (一)跳转的思路: 1.打开软件,只显示登录界面(隐藏游戏界面.暂停界面.玩家死亡界面) 2.点击微信登录(QQ登录)跳转到游戏界面,隐藏登录界面 3. ...

  8. Node.js平台的一些使用总结

    Node.js的安装 菜鸟教程 npm -v查看npm的版本. npm更新 npm官网 npm权限问题 由于npm经常会因为权限问题,不能全局安装模块,所以解决办法如下: npm官网 npm切换淘宝源 ...

  9. mysql超时机制

    mysql每次建立一个socket连接(connect)时,这个socket都会占用一定内存.即使你关闭(close)连接时,并不是真正的关闭,而是处于睡眠(sleep)状态. 当你下次再进行连接时, ...

  10. Golang 网络爬虫框架gocolly/colly 二 jQuery selector

    Golang 网络爬虫框架gocolly/colly 二 jQuery selector colly框架依赖goquery库,goquery将jQuery的语法和特性引入到了go语言中.如果要灵活自如 ...