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的概 ...
随机推荐
- 清除浮动小记,兼容Ie6,7
.clearfix { *zoom:1;} .clearfix:after{clear:both; display:block; height:0; visibility:hidden; line-h ...
- CSS 绝对定位与弹性布局合作居中
position: absolute; display:flex; justify-content:center;align-items:center;
- 通过ClientDataSet复制表的结构及数据
1. 需要2个ClientDataSet组件: 2. clientDataSet1连接目标表,clientDataSet2连接源表,如果无法直接连接,使用DataSetProvider进行桥接: ...
- ASP.NET MVC中在 @RenderBody() 或者 @Html.Partial()中需要使用引入外部js,css
今天想在后台封装一下bootstraptree这个插件,引入jquery.js bootstrap.js bootstrap.css bootstrap-tree.js后,我在页面查看脚本错误就连最简 ...
- Visual Studio Code运行Python文件出现 “Linter pylint is not installed ”提示解决办法
运行Python代码后出现 “Linter pylint is not installed ”提示 只需要添加一行代码就可以解决 { "python.pythonPath": &q ...
- [USACO12NOV]同时平衡线Concurrently Balanced Strings DP map 思维
题面 [USACO12NOV]同时平衡线Concurrently Balanced Strings 题解 考虑DP. \(f[i]\)表示以\(i\)为左端点的合法区间个数.令\(pos[i]\)表示 ...
- 洛谷 P1685 游览 解题报告
P1685 游览 题目描述 顺利通过了黄药师的考验,下面就可以尽情游览桃花岛了! 你要从桃花岛的西头开始一直玩到东头,然后在东头的码头离开.可是当你游玩了一次后,发现桃花岛的景色实在是非常的美丽!!! ...
- Mac OS 装gdb
1 要求按照mac ports 2 命令:sudo port install gdb 3 安装位置在: /opt/local/bin/ggdb , 注意,ggdb是执行命令
- Linux编程中 #define _XOPEN_SOURCE的作用
[误解]#define _XOPEN_SOURCE决不是简单的宏定义它是使程序符合系统环境的不可缺少的部分 [概念]Glibc 所实现全部或部分规范下的功能有:1.ISO C: C语言国际标准. 2. ...
- Android Log详解(Log.v,Log.d,Log.i,Log.w,Log.e)
1.Log.v 的调试颜色为黑色的,任何消息都会输出,这里的v代表verbose啰嗦的意思,平时使用就是Log.v("",""); 2.Log.d的输出颜色是蓝 ...