zoukankan      html  css  js  c++  java
  • Codeforces Round #371 (Div. 2)

    题目链接:http://codeforces.com/contest/714/problem/A

    题意:有两个人A,B 给定A的时间区间[L1,R1], B的时间区间[L2,R2],然后在正好K分钟的时候A小时一分钟,即K这一分钟A不在。现在问A和B在时间上能相遇多久。

    思路:相遇的区间是[max(L1,L2),min(R1,R2)],然后判断K是否在这个区间里就好了。 还有可能相遇的区间大小为负数即A和B不相遇

    #define _CRT_SECURE_NO_DEPRECATE
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<string>
    #include<queue>
    #include<vector>
    #include<time.h>
    #include<cmath>
    #include<stack>
    using namespace std;
    typedef long long int LL;
    #include <cstdio>
    const int MAX = 2000 + 5;
    int main(){
    //#ifdef kirito
    //    freopen("in.txt", "r", stdin);
    //    freopen("out.txt", "w", stdout);
    //#endif
        LL l1, l2, r1, r2, k;
        while (~scanf("%I64d%I64d%I64d%I64d%I64d", &l1, &r1, &l2, &r2, &k)){
            LL L = max(l1, l2);
            LL R = min(r1, r2);
            LL ans = R - L + 1;
            if (k >= L&&k <= R){
                ans--;
            }
            if (ans < 0){ ans = 0; }
            cout << ans << endl;
        }
        return 0;
    }
  • 相关阅读:
    HTML入门之003
    html入门之002
    HTML入门之001
    端口
    计算机基础
    二进制的学习
    markdown基础
    css基础
    html基础之三
    html基础之二
  • 原文地址:https://www.cnblogs.com/kirito520/p/5872791.html
Copyright © 2011-2022 走看看