解题思路:
【题意】
Sonya每天只有[l1,r1]时间段内空闲,且在k时刻,她要打扮而不能够见Filya
Filya每天[l2,r2]时间段内空闲
问他们俩每天有多少时间能够在一起
【类型】
区间交
【分析】
显然,要求他们俩每天有多少时间在一起
其实就是求两区间的交集
那无外乎就是对两区间的位置关系进行分析
,。当然还有几个图这里就不一一列举了,主要就是找到两个的
相交区间,然后判断e是否在这个区间中,在的话减一;
<pre name="code" class="html">#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
long long a, b, c, d, e, f, ans;
cin >> a >> b >> c >> d >> e;
ans = min(b, d) - max(a, c) + 1;
if ( e <= min(b, d) && max(a, c) <= e)
ans--;
if (ans < 0)
{
cout << "0" << endl;
return 0;
}
<span style="white-space:pre"> </span>else
cout << ans << endl;
return 0;
}