Codeforces Round #371 (Div. 2) - A
题目链接: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; }