zoukankan      html  css  js  c++  java
  • Codeforces Round #371 (Div. 2) A. Meeting of Old Friends 水题

    A. Meeting of Old Friends

    题目连接:

    http://codeforces.com/contest/714/problem/A

    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 ≤ 1018, 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

    Hint

    题意

    给你两个区间,然后去掉k,问你相交的区间大小是多少

    题解:

    水题

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        long long l1,r1,l2,r2,k;
        scanf("%lld%lld%lld%lld%lld",&l1,&r1,&l2,&r2,&k);
        if(l2>r1||l1>r2)
        {
            cout<<"0"<<endl;
            return 0;
        }
        else
        {
            long long l=max(l1,l2);
            long long r=min(r1,r2);
            long long ans=r-l+1;
            if(k<=r&&k>=l)ans--;
            cout<<ans<<endl;
        }
    }
  • 相关阅读:
    RabbitMQ安装
    基于Linux的校园网破解思路和方法
    网络-0001-常见传输介质
    友情链接
    linux简史
    计算机的发展简史
    ArrayList&LinkedList&Vector区别
    Adobe Flash Player PPAPI 32.0.0.330
    ntoskrnl.exe导致蓝屏解决方法
    Git常用命令
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5874486.html
Copyright © 2011-2022 走看看