Description

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 l1r1l2r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018l1 ≤ r1l2 ≤ 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.

Sample Input

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

Hint

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.

算是一道非常非常简单的贪心做法题吧。

但我还是WA了无数发,只因为那个被我犯过好几次的错误,不是第一次犯这种错了。

只考虑到了两个区间相交和相离的情况,没有考虑到内含的情况。

这题应该注意的是k是在相交区间断点的问题。

 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<iostream>
using namespace std;
typedef long long LL; struct con{
LL head;
LL tail;
}con[];
LL cmp(struct con a,struct con b)
{
if(a.head==b.head)
return a.tail<b.tail;
return a.head<b.head;
}
int main()
{
LL i,p,j,n;
LL k,ans=;
// scanf("%lld",&p);
// printf("%lld\n",p);
for(i=;i<=;i++)
{
scanf("%lld%lld",&con[i].head,&con[i].tail);
}
scanf("%lld",&k);
sort(con,con+,cmp); if(con[].head<=con[].tail&&(k>con[].tail||k<con[].head))
{
ans=con[].tail-con[].head+;
}
if(con[].head<=con[].tail&&(k<=con[].tail&&k>=con[].head))
{
ans=con[].tail-con[].head;
}
if(con[].tail>=con[].tail&&(k>con[].tail||k<con[].head))
{
ans=con[].tail-con[].head+;
}
if(con[].tail>=con[].tail&&(k<=con[].tail&&k>=con[].head))
{
ans=con[].tail-con[].head;
}
printf("%lld\n",ans);
return ;
}

CodeForces 714A的更多相关文章

  1. Codeforces 714A Meeting of Old Friends

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

  2. Codeforces 714A 朋友聚会

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

  3. 2018SDIBT_国庆个人第六场

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

  4. CSUST 8.5 早训

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

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

随机推荐

  1. 【Leetcode】143. Reorder List

    Question: Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You ...

  2. [转贴]Linux的SUID SGID 等知识内容

    作者:sparkdev 出处:http://www.cnblogs.com/sparkdev/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接, ...

  3. uva 1513(线段树)

    题目链接:1513 - Movie collection 题意:有一堆电影,按1-n顺序排,有m次操作,每次询问第ai个电影之前有多少个电影,然后将其抽出放在堆顶. 分析:线段树应用. 因为每次查询后 ...

  4. day02--Python基础二(基础数据类型)

    一.数据与数据类型 1 什么是数据? x=10,10是我们要存储的数据 2 为何数据要分不同的类型 数据是用来表示状态的,不同的状态就应该用不同的类型的数据去表示 3 数据类型 数字(int) 字符串 ...

  5. 安装Zookeeper出现Unable to start AdminServer,existing abnormally问题解决方法

    问题如下: 出现这个问题主要是由于8080端口占用,可在zoo.cfg中增加admin.serverPort=没有被占用的端口号解决问题.

  6. Java的StringBuIlder扩容机制

    JDK 1.6中,扩容的源码是这样: void expandCapacity(int minimumCapacity) { int newCapacity = (value.length + 1) * ...

  7. HDU4734——2013 ACM/ICPC Asia Regional Chengdu Online

    今天做的比赛,和队友都有轻微被虐的赶脚. 诶,我做的题就是这个题目了. 题目描述就是对于一个十进制数数位上的每一位当做一个二进制位来求出这个数,这个定义为G(x). 题目给定你A和B,求在0-B范围内 ...

  8. 设置Linux终端字体颜色

    系统启动后,环境变量加载的顺序为:/etc/profile → /etc/profile.d/*.sh → ~/.bash_profile → ~/.bashrc → /etc/bashrc 想要修改 ...

  9. [POI2012]STU-Well

    题意翻译 给定一个非负整数序列A,每次操作可以选择一个数然后减掉1,要求进行不超过m次操作使得存在一个Ak=0且max⁡(∣xi−xi−1∣)最小,输出这个最小值以及此时最小的k (1≤n≤1 000 ...

  10. [postfix]转发邮件设置

    http://stackoverflow.com/questions/22537523/postfix-recipient-bcc-maps-multiple-recipients-how-to ht ...