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 ...
随机推荐
- [LeetCode] 二叉树相关题目(不完全)
最近在做LeetCode上面有关二叉树的题目,这篇博客仅用来记录这些题目的代码. 二叉树的题目,一般都是利用递归来解决的,因此这一类题目对理解递归很有帮助. 1.Symmetric Tree(http ...
- JavaScript数字例子,二分法,冒泡排序
先看一下两个例子: 十个成绩,求总分,最高分,最低分 //输入10个成绩,求总分,最高,最低 var arr=new Array(67,45,56,12,90,98,23,43,56,99,97); ...
- Swift 开源项目练习应用
小的View.动画实现练习 拥有着苹果先天生态优势的Swift自发布以来,各种优秀的开源项目便层出不穷.本文作者站在个人的角度,将2014年Swift开源项目做了一个甄别.筛选,从工具.存储.网络.界 ...
- SpringJDBC的JdbcTemplate在MySQL5.7下不支持子查询的问题
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [ SELECT ...
- du 命令详解
du : show disk usage 作用:统计目录或文件所占用磁盘空间的大小. 语法:du 参数 选项 参数: -a 为每个制定文件显示磁盘使用情况, 或者为目录中每个文件显示各自磁盘使用情况 ...
- 虚拟机下linux系统安装nginx
近在windows虚机下安装nginx,也遇到部分问题,写篇随笔总结一下 一.安装虚机 windows下安装虚拟机我就不说了,一搜一大把,一直下一步就ok了 二. 打开虚拟安装nginx 1.选择版本 ...
- appium 解锁九宫格
很多人在自动化的过程中,对解锁9宫格有很多麻烦,特别是app上的有些整个放在整个view中,这就给我们测试解锁九宫格带来问题了,笔者尝试了去解决,但是都没有找到一个很好的方案,那么我就试着先去通过安卓 ...
- Mac_OS_Sierra_10.12.6编译OpenJDK9
编译环境以及依赖 macOS:Sierra,10.12.6 处理器:2.6 GHz Intel Core i7 内存:16 GB 2133 MHz LPDDR3 Command Line Tools ...
- Linux 文本编辑器vi命令
1.Vim Vim 是一个功能强大的全屏幕文本编辑器,是 Linux/UNIX 上最常用的文本编辑器,它的作用是建立.编辑.显示文本文件. Vim 没有菜单,只有命令 2.Vim 工作模式 3.插入 ...
- VC6.0 突然打不开dsw 工程文件的解决方案
在vc编程中,经常遇到dsw工程文件无法打开,或者打开后看不到类和变量的问题.特别是把代码从一台电脑上copy到另一台电脑上以后,常常会碰到这种奇怪的问题.有时在编辑状态下也会发生成员变量或函数提示不 ...