ZCMU-1772-区间交集

1772: Meeting of Old Friends

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 95   Solved: 28
[ Submit][ Status][ Web Board]

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 l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 10^18, 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.

Sample Input

1 10 9 20 1

Sample Output

2


【解析】

文章大意就是一个动物要去见另外一个动物,一个动物醒着的时间已知,另一个动物去的时间也知道,然后在k这

时间它要化妆不见客。这个其实就是求交集,这个我WA了很多次...没办法数学实在是....

#include
#include
#include
using namespace std;
int main()
{
    long long a,b,c,d,k,count;
    while(~scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&k))
    {
        count=0;
        if(c<=b&&a<=d)//判断符不符合条件看看有没有交集
        {
            if(ad)
                b=d;//去两者中小的
            count=b-a+1;//两者相减加1算见面的时间
            if(k>=a&&k<=b)
              count--;//如果K在区间内,我们就减去1,因为在那个时间它要化妆
              printf("%lld\n",count);
        }
        else
            printf("0\n");
    }
    return 0;
}



你可能感兴趣的:(ACM)