Anton 上课题
Anton 上课题
Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes.
Anton has n variants when he will attend chess classes, i-th variant is given by a period of time (l1, i, r1, i). Also he has m variants when he will attend programming classes, i-th variant is given by a period of time (l2, i, r2, i).
Anton needs to choose exactly one of n possible periods of time when he will attend chess classes and exactly one of m possible periods of time when he will attend programming classes. He wants to have a rest between classes, so from all the possible pairs of the periods he wants to choose the one where the distance between the periods is maximal.
The distance between periods (l1, r1) and (l2, r2) is the minimal possible distance between a point in the first period and a point in the second period, that is the minimal possible |i - j|, where l1 ≤ i ≤ r1 and l2 ≤ j ≤ r2. In particular, when the periods intersect, the distance between them is 0.
Anton wants to know how much time his rest between the classes will last in the best case. Help Anton and find this number!
Input:
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of time periods when Anton can attend chess classes.
Each of the following n lines of the input contains two integers l1, i and r1, i (1 ≤ l1, i ≤ r1, i ≤ 109) — the i-th variant of a period of time when Anton can attend chess classes.
The following line of the input contains a single integer m (1 ≤ m ≤ 200 000) — the number of time periods when Anton can attend programming classes.
Each of the following m lines of the input contains two integers l2, i and r2, i (1 ≤ l2, i ≤ r2, i ≤ 109) — the i-th variant of a period of time when Anton can attend programming classes.
Output:
Output one integer — the maximal possible distance between time periods.
Examples:
3
1 5
2 6
2 3
2
2 4
6 8
3
3
1 5
2 6
3 7
2
2 4
1 4
0 Note
In the first sample Anton can attend chess classes in the period (2, 3) and attend programming classes in the period (6, 8). It's not hard to see that in this case the distance between the periods will be equal to 3.
In the second sample if he chooses any pair of periods, they will intersect. So the answer is 0.
题目大意:Anton要去上两个课程,但是每个课程都有多种选择,问你哪种选择可以使Anton的休息时间更长,并求出休息时间,假如所有的课程都出现了时间重叠,那么输出答案-1。
解题思路:我们只需要找出第一个课程的最早结束时间和第二个课程的最晚结束时间然后相减就得出了答案,因为我们并不知道先上哪个课程最好,所以我们把两种情况都算出来然后比较最优解就行了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue> using namespace std;
const int MAX=;
int n,m; struct De
{
int a,b;
};
De xang[MAX],bian[MAX]; bool cmp(De x,De y)
{
return x.b>y.b;
} bool cep(De x,De y)
{
return x.a>y.a;
} int main()
{
scanf("%d",&n);
int ans1,ans2;
for(int i=;i<n;i++)
scanf("%d %d",&xang[i].a,&xang[i].b);
scanf("%d",&m);
for(int i=;i<m;i++)
scanf("%d %d",&bian[i].a,&bian[i].b);
sort(xang,xang+n,cmp);
sort(bian,bian+m,cep);
ans1=bian[].a-xang[n-].b;
sort(xang,xang+n,cep);
sort(bian,bian+m,cmp);
ans2=xang[].a-bian[m-].b;
if(ans1<=&&ans2<=) printf("0\n");
else printf("%d\n",ans1>ans2?ans1:ans2);
return ;
}
Anton 上课题的更多相关文章
- 【腾讯Bugly干货分享】OCS——史上最疯狂的iOS动态化方案
本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:https://mp.weixin.qq.com/s/zctwM2Wf8c6_sxT_0yZvXg 导语 在 ...
- 年终巨献 史上最全 ——LINQ to SQL语句
LINQ to SQL语句(1)之Where 适用场景:实现过滤,查询等功能. 说明:与SQL命令中的Where作用相似,都是起到范围限定也就是过滤作用的,而判断条件就是它后面所接的子句.Where操 ...
- JVM 平台上的各种语言的开发指南
JVM 平台上的各种语言的开发指南 为什么我们需要如此多的JVM语言? 在2013年你可以有50中JVM语言的选择来用于你的下一个项目.尽管你可以说出一大打的名字,你会准备为你的下一个项目选择一种新的 ...
- 写在MongoCola在Github上获得200个Star之后
MongoCola MongoCola是一个开源的MongoDB管理工具. 由于最初版本的设计失误,所以现在只能在Windows上使用,虽然可以在OSX上使用,但是非常别扭. 契机 MongoCola ...
- DB层面上的设计 分库分表 读写分离 集群化 负载均衡
第1章 引言 随着互联网应用的广泛普及,海量数据的存储和访问成为了系统设计的瓶颈问题.对于一个大型的 互联网应用,每天几十亿的PV无疑对数据库造成了相当高的负载.对于系统的稳定性和扩展性造成了极大的 ...
- 对话机器学习大神Yoshua Bengio(上)
Yoshua Bengio教授(个人主页)是机器学习大神之一,尤其是在深度学习这个领域.他连同Geoff Hinton老先生以及 Yann LeCun(燕乐存)教授,缔造了2006年开始的深度学习复兴 ...
- Spark Streaming揭秘 Day20 动态Batch size实现初探(上)
Spark Streaming揭秘 Day20 动态Batch size实现初探(上) 今天开始,主要是通过对动态Batch size调整的论文的解析,来进一步了解SparkStreaming的处理机 ...
- SaaS系列介绍之六: SaaS模式分析(上)
1 引言 如果我们想要更多的玫瑰花,就必须种植更多的玫瑰树. ________姚群<成功激励格言精选> SaaS模式是个新兴的话题,有 ...
- 在MVC中利用uploadify插件实现上传文件的功能
趁着近段的空闲时间,开发任务不是很重,就一直想把以前在仓促时间里所写的多文件上传功能改一下,在网上找了很多例子,觉得uploadify还可以,就想用它来试试.实现自己想要的功能.根据官网的开发文档,同 ...
随机推荐
- leetCode21: 合并两个有序列表
将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1->3->4 输出:1->1->2- ...
- Requests将verify设置为False后取消警告的方式
方法一 import requests import urllib3 urllib3.disable_warnings() resp = requests.get('https://www.***.c ...
- uva-10245-分治
题意:数组二维空间内的点,求最近的俩个点的距离. 根据x排序,求左部分的最近距离,右部分最近距离,然后以中点,当前距离为半径,计算所有的点距离. #include <string> #in ...
- K8s之配置文件kubeconfig生成
在开启了 TLS 的集群中,每当与集群交互的时候少不了的是身份认证,使用 kubeconfig(即证书) 和 token 两种认证方式是最简单也最通用的认证方式. 以kubectl为例介绍kubeco ...
- C# 反编译
今儿也是运气背,不知怎么的,一脚就把电脑踢关机了(其实就轻轻碰到了一下主机),我去,写了一早上的代码,尼玛就不见,不见就算了,其实是保存了的,主要是文件还损坏了,尼玛,那心情!!! 然后就想着恢复,下 ...
- 2019/1/9 6系列所有装置编号与SIM卡信息抓取
一.报错:File "G:/station/6系列装置信息明细.py", line 12, in <module>workbook.save(r'.\6系列装置明细表. ...
- Process 开启子进程 的两种方式、join控制子进程、守护进程
一.join控制子进程的一种方式 当主进程需要在子进程结束之后结束时,我们需要用到join来控制子进程. import time import random from multiprocessing ...
- 浏览器useragent
var ua = window.navigator.userAgent; edge :Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537 ...
- redis、mysql、mongdb的比较
特点: 1-1 MySQL:1. 使用c和c++编写,并使用了多种编译器进行测试,保证源代码的可移植性2. 支持多种操作系统3. 为多种编程语言提供可API4. 支持多线程,充分利用CPU资源优化的S ...
- 3U - 算菜价
妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐.现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵. Input 输入含有一些数据组,每组数据包括菜种( ...