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
2
1 100 50 200 75
50
In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
题目链接:http://codeforces.com/problemset/problem/714/A
解题思路:
【题意】
Sonya每天只有[l1,r1]时间段内空闲,且在k时刻,她要打扮而不能够见Filya
Filya每天[l2,r2]时间段内空闲
问他们俩每天有多少时间能够在一起
【类型】
区间交
【分析】
显然,要求他们俩每天有多少时间在一起
其实就是求两区间的交集
那无外乎就是对两区间的位置关系进行分析
,。当然还有几个图这里就不一一列举了,主要就是找到两个的
相交区间,然后判断k是否在这个区间中,在的话减一;
这道题要用long long,否则会超!
下面给出AC代码:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
ll l1,l2,r1,r2,k;
while(cin>>l1>>r1>>l2>>r2>>k)
{
ll minn = min(r1,r2);
ll maxn = max(l1,l2);
ll ans = minn-maxn+;
if(maxn > minn)
{
cout<<<<endl;
continue;
}
if(k >= maxn && k <= minn)
ans--;
cout<<ans<<endl;
}
return ;
}
Codeforces 714A Meeting of Old Friends的更多相关文章
- Codeforces 714A 朋友聚会
参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6395268.html A. Meeting of Old Friends time limit p ...
- CodeForces 714A
Description Today an outstanding event is going to happen in the forest — hedgehog Filya will come t ...
- CodeForces 144B Meeting
暴力. 题目只要求计算边上的点就可以了,一开始没看清题意,把内部的也算进去了.内部的计算可以延迟标记一下,但这题没有必要. #include<map> #include<set> ...
- CodeForces A. Meeting of Old Friends
2019-05-30 20:19:57 加油!!! sort(a + 1, a + 5); 卡了一会儿 #include <bits/stdc++.h> using namespace s ...
- CSUST 8.5 早训
## Problem A A - Meeting of Old Friends CodeForces - 714A 题意: 解题说明:此题其实是求两段区间的交集,注意要去除掉交集中的某个点. 题解: ...
- 2018SDIBT_国庆个人第六场
A - A codeforces 714A Description Today an outstanding event is going to happen in the forest — hedg ...
- codeforces 782B The Meeting Place Cannot Be Changed (三分)
The Meeting Place Cannot Be Changed Problem Description The main road in Bytecity is a straight line ...
- Codeforces Round #375 (Div. 2) A. The New Year: Meeting Friends 水题
A. The New Year: Meeting Friends 题目连接: http://codeforces.com/contest/723/problem/A Description There ...
- 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 out ...
随机推荐
- DotNetCore跨平台~为Lind.DotNetCore框架添加单元测试的意义
回到目录 单元测试大叔认为有几下两个必要的作用,也是为什么要上单元测试的原因 组件,框架在修改和BUG解决后,进行正确性的测试,然后才能打包 业务模块,主要提现在进行业务规则的模拟上面,保证了业务逻辑 ...
- IP地址简介
IP地址 IP地址,Internet Protocol Address,网络协议地址: IP地址与网络接口绑定,并不是指向一台主机,一个主机可能有多个IP地址,如果其连接多个网络,有多个网络接口: I ...
- http中的get和post(二)
博客园精华区有篇文章< GET 和 POST 有什么区别?及为什么网上的多数答案都是错的 >,文中和回复多是对以下两个问题进行了深究: 长度限制 Url 是否隐藏数据 在我看来这两者都不是 ...
- 创建一个可用的简单的SpringMVC项目,图文并茂
转载麻烦注明下来源:http://www.cnblogs.com/silentdoer/articles/7134332.html,谢谢. 最近在自学SpringMVC,百度了很多资料都是比较老的,而 ...
- 高性能管线式HTTP请求(实践·原理·实现)
该篇实际是介绍pipe管线的原理,下面主要通过其高性能的测试实践,解析背后数据流量及原理.最后附带一个简单的实现 实践 先直接看对比测试方法 对于单一客户端对服务器进行http请求,一般我 ...
- PHP判断手机号运营商(详细介绍附代码)
道理很简单,知道手机号规则 进行正则判断就可以 移动:134.135.136.137.138.139.150.151.157(TD).158.159.187.188 联通:130.131.132.15 ...
- 浅析Node.js的Event Loop
目录 浅析Node.js的Event Loop 引出问题 Node.js的基本架构 Libuv Event Loop Event Loop Phases Overview Poll Phase The ...
- maven jar包冲三种解决方式
初次启动应用,一直包如下错误,起初怀疑引入pandora 版本冲突. Exception in thread "main" java.lang.NoSuchMethodError: ...
- 4、公司经营的业务来源 - CEO之公司管理经验谈
公司经营的业务来源为公司的运作资金提供了帮助,一般来说,整个公司的领导层为公司的经营做管理,而业务员就为公司的业务提供来源,然后建设部为业务开展做建设. 一.总经理: 公司的总经理主要负责公司运作经营 ...
- Lambda 表达式,Java中应用Lambda 表达式
一.Lambda 表达式 简单来说,编程中提到的 lambda 表达式,通常是在需要一个函数,但是又不想费神去命名一个函数的场合下使用,也就是指匿名函数. 链接:知乎 先举一个普通的 Python 例 ...