CodeForces 714A
Description
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.
Input
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.
Output
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
Sample Input
1 10 9 20 1
2
1 100 50 200 75
50
Hint
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.
算是一道非常非常简单的贪心做法题吧。
但我还是WA了无数发,只因为那个被我犯过好几次的错误,不是第一次犯这种错了。
只考虑到了两个区间相交和相离的情况,没有考虑到内含的情况。
这题应该注意的是k是在相交区间断点的问题。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<iostream>
using namespace std;
typedef long long LL; struct con{
LL head;
LL tail;
}con[];
LL cmp(struct con a,struct con b)
{
if(a.head==b.head)
return a.tail<b.tail;
return a.head<b.head;
}
int main()
{
LL i,p,j,n;
LL k,ans=;
// scanf("%lld",&p);
// printf("%lld\n",p);
for(i=;i<=;i++)
{
scanf("%lld%lld",&con[i].head,&con[i].tail);
}
scanf("%lld",&k);
sort(con,con+,cmp); if(con[].head<=con[].tail&&(k>con[].tail||k<con[].head))
{
ans=con[].tail-con[].head+;
}
if(con[].head<=con[].tail&&(k<=con[].tail&&k>=con[].head))
{
ans=con[].tail-con[].head;
}
if(con[].tail>=con[].tail&&(k>con[].tail||k<con[].head))
{
ans=con[].tail-con[].head+;
}
if(con[].tail>=con[].tail&&(k<=con[].tail&&k>=con[].head))
{
ans=con[].tail-con[].head;
}
printf("%lld\n",ans);
return ;
}
CodeForces 714A的更多相关文章
- Codeforces 714A Meeting of Old Friends
A. Meeting of Old Friends time limit per test:1 second memory limit per test:256 megabytes input:sta ...
- Codeforces 714A 朋友聚会
参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6395268.html A. Meeting of Old Friends time limit p ...
- 2018SDIBT_国庆个人第六场
A - A codeforces 714A Description Today an outstanding event is going to happen in the forest — hedg ...
- CSUST 8.5 早训
## Problem A A - Meeting of Old Friends CodeForces - 714A 题意: 解题说明:此题其实是求两段区间的交集,注意要去除掉交集中的某个点. 题解: ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- javascript定时保存表单数据的代码
(忘记是不是两家邮箱都有这个功能). 那这个功能是怎么做的呢? 定时,我们知道怎么弄,但保存呢?也许我们会通过隐藏域等手段来存放数据.但是,这个却有个缺点:那就是刷新页面后,数据将会丢失. 而此时,就 ...
- Java机器学习框架deeplearing4j入门教程
1.添加项目maven添加依赖 or 导入jar包 or 使用jvm <project xmlns="http://maven.apache.org/POM/4.0.0" x ...
- D-Separation(D分离)-PRML-8.22-Graphical Model 五 18 by 小军
D-Separation(D分离)-PRML-8.22-Graphical Model 五18by 小军 一.引言 在贝叶斯网络的学习过程中,经常会遇到(D-Separation)D-分离这个概念 ...
- Educational Codeforces Round 56 Div. 2 翻车记
A:签到. B:仅当只有一种字符时无法构成非回文串. #include<iostream> #include<cstdio> #include<cmath> #in ...
- 回车”(carriage return)和”换行”(line feed)的区别和来历-(附:ASCII表)
这两天研究小票打印机编程手册,遇到这样一个问题: LF,即Line Feed,中文意思“换行”:CR,即Carriage Return,中文意思“回车”.但是我们通常把这两个混为一谈.既然设置 ...
- P3455 [POI2007]ZAP-Queries
题目描述 Byteasar the Cryptographer works on breaking the code of BSA (Byteotian Security Agency). He ha ...
- MT【121】耐克数列的估计
已知$\{a_n\}$满足$a_1=1,a_2=2,\dfrac{a_{n+2}}{a_n}=\dfrac{a_{n+1}^2+1}{a_n^2+1}$, 求$[a_{2017}]$_____ 解:容 ...
- Android Emoji兼容包使用详解
Emoji兼容性 我们经常会遇到这样的问题: 给朋友发的emoji表情, 在自己手机上展示是正常的, 但是到朋友手机上, 却没有展示出来, 或者展示出来了, 但是也跟自己手机上展示的不一样. 所以, ...
- Ld, -rpath, -rpath-link
http://blog.csdn.net/xph23/article/details/38157491
- [POI2011]ROT-Tree Rotations
发现x的子树在后续处理中不会影响逆序对的情况(只关心有哪些值,相对位置已经不重要了) f[x]表示x为根的子树最小逆序对数 考虑左右儿子交换与否. 暴力是O(n^2)的 考虑线段树合并 左右儿子线段树 ...