题目描述:
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.
输入描述:
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.
输出描述:
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
输入:
1 10 9 20 1
1 100 50 200 75
输出:
2
50
题意:
一个人可以在时间段 l1 到 r1 处于清醒状态, 且需要在 k 时为自己化妆,在 l2 到 r2 时间段去访问自己的朋友, 问它能和自己的朋友在一起待多久时间.
题解:
暴力。
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
ll l1,l2,r1,r2,k;
while(scanf("%I64d%I64d%I64d%I64d%I64d",&l1,&r1,&l2,&r2,&k)!=EOF){
ll ans = min(r1,r2) - max(l1,l2) + 1;
ll l = max(l1,l2);
ll r = min(r1,r2);
if(k >= l && k <= r) ans --;
if(l1 > r2) printf("0\n");
else if(l2 > r1) printf("0\n");
else printf("%I64d\n",ans);
}
return 0;
}