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的概 ...
随机推荐
- From 易水寒 格局越大 人生越宽
有这么一则故事:三个泥瓦匠在砌墙,一个人走过来,问他们在干什么. 第一个泥瓦匠没好气地说,你没看见吗?我在辛苦地砌墙呢.第二个回答,我们正在建一座高楼.第三个则洋溢着喜悦说,我们正在创造美好生活. 1 ...
- [转帖]TLS 1.3概述
TLS 1.3概述 http://www.inforsec.org/wp/?p=1960 By Yanting Yang | 四月 26, 2017| SecComm 作者:李新宇 中科院软件所 ...
- Anaconda多版本Python管理以及TensorFlow版本的选择安装
Anaconda是一个集成python及包管理的软件,记得最早使用时在2014年,那时候网上还没有什么资料,需要同时使用py2和py3的时候,当时的做法是同时安装Anaconda2和Anaconda3 ...
- [BinaryTree] AVL树、红黑树、B/B+树和Trie树的比较
转自:AVL树.红黑树.B/B+树和Trie树的比较 AVL树 最早的平衡二叉树之一.AVL是一种高度平衡的二叉树,所以通常的结果是,维护这种高度平衡所付出的代价比从中获得的效率收益还大,故而实际的应 ...
- js复制内容到剪切板
注意第一部分的内容不兼容Safari,全兼容的请使用第二部分方法 第一部分 查看demo请点 这里. 原生js复制指定内容到剪切板,超简单的实现方式, 实现思路如下: 1.创建一个input,把想要 ...
- Satisfiability of Equality Equations - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Satisfiability of Equality Equations - LeetCode 注意点 必须要初始化pre 解法 解法一:典型的并查集算法 ...
- Android 5.0 Lollipop SDK下载地址(PASS)
Android 5.0 ARM EABI v7a System Image https://dl-ssl.google.com/android/repository/sys-img/google_ap ...
- Android Layout_weight 属性
Android 对Layout_weight属性完全解析以及使用ListView来实现表格http://blog.csdn.net/xiaanming/article/details/13630837 ...
- hdu 5852 :Intersection is not allowed! 行列式
有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,bk). ...
- 【数学】【P5150】 生日礼物
Description 给定 \(n\),求 \[\sum_{i}~\sum_j~[lcm(i,j)~=~n]\] input 一行一个整数代表 \(n\) Output 一行一个整数代表答案 Hin ...