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 ...
随机推荐
- 引号在jsp页面中正确显示的处理
写在前面: 在前面的博客中已经有了对一些特殊字符的处理,但是万万没有想到,出来了一个含有引号的字符串,比如这样的ab"c"d的一个字符串.如果在超链接传值的时候,会与前面的引号成对 ...
- iOS 本地项目上传github,github管理项目配置
一.注册github账号 首先需要注册一个github账号,注册地址:https://github.com 接着会来到这 然后会收到一封github发的邮件,进入邮箱验证 二.创建个人的githu ...
- iOS UI特效
1.iOS特效 a.对应APP中的基本动作分三类: 1.指向性动效(滑动,弹出等) 2.提示性动效(滑动删除,下拉刷新等) 3.空间扩展(翻动,放大等) b.这类动效在设计过程中需要主意几点: 1.系 ...
- ReactNative布局样式总结
flex number 用于设置或检索弹性盒模型对象的子元素如何分配空间 flexDirection enum('row', 'row-reverse' ,'column','column-rever ...
- ArcGIS 网络分析[8.2] 资料2 使用IDatasetContainer2接口的CreateDataset方法创建网络数据集
上节提及如何使用IDatasetContainer2接口访问到网络数据集,上例可以封装为一个方法. 这节就使用IDatasetContainer2接口(Geodatabase类库)的CreateDat ...
- git正确的删除远程仓库的文件并用.gitignore忽略提交此文件
我向远程仓库提交了如下文件src/ pom.xml target/ WebContent/,发现没必要提交target目录. 于是做了如下操作: git rm -r --cached target g ...
- hello world 为什么我们看到学习中有这一句话!!!
Hello World ,中文意思:你好,世界.世界上的第一个程序就是Hello World,由Brian Kernighan创作. Hello, world"程序是指在计算机屏幕上输出“H ...
- precmd:6: job table full or recursion limit exceeded
使用GDC Data Transfer Tool下载10999个isoforms.quantification.txt文件时,写了shell循环的小脚本: cat all_id_file |while ...
- 【原创】java NIO FileChannel 学习笔记 新建一个FileChannel
首先使用FileChannel 的open方法获取一个FileChannel对象.下面这段代码是FileChannel中open方法的代码. public static FileChannel ope ...
- 第一个Vue插件从封装到发布
前言 这是我封装的第一个Vue插件,实现的功能是滑动选择省市区,虽然只是一个简单的插件,但还是挺开心的,记录一下步骤. 插件地址:https://github.com/leichangchun/vue ...