Codeforces--714A--Meeting of Old Friends

题目描述:
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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值