【题目链接】:http://codeforces.com/contest/785/problem/B

【题意】



给你两个时间各自能够在哪些时间段去完成;

让你选择两个时间段来完成这两件事情;

要求两段时间的间隔最长(休息的时间最长)

【题解】



考虑最后的答案;

只会是

    (l,r).....(left,right)

    (left,right)...(l,r)

    else

这3种情况

对于第一种记录第一件事右端点的最小值,第二件事左端点的最大值;

对于第二种记录第二件事右端点的最小值,第一件事左端点的最大值;

用这两种情况尝试更新答案;

如果答案不为0,则输出它,否则剩下的情况都是相交的;直接输出0就好;



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110; int l, r, left, right,zdl=0,zxr=1e9,zdleft=0,zxright=1e9;
int n, m,x,y,ans = 0; void input_data()
{
rei(n);
rep1(i, 1, n)
{
rei(x), rei(y);
zxr = min(zxr, y);
zdl = max(zdl, x);
}
rei(m);
rep1(i, 1, m)
{
rei(x), rei(y);
zxright = min(zxright, y);
zdleft = max(zdleft, x);
}
} void get_ans()
{
if (zxr <= zdleft)
ans = max(ans, zdleft - zxr);
if (zxright <= zdl)
ans = max(ans, zdl - zxright);
} void o()
{
cout << ans << endl;
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
input_data();
get_ans();
o();
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 785B】Anton and Classes的更多相关文章

  1. 【27.91%】【codeforces 734E】Anton and Tree

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【29.89%】【codeforces 734D】Anton and Chess

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【13.77%】【codeforces 734C】Anton and Making Potions

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【81.37%】【codeforces 734B】Anton and Digits

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【77.39%】【codeforces 734A】Anton and Danik

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【25.00%】【codeforces 584E】Anton and Ira

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【codeforces 508B】Anton and currency you all know

    [题目链接]:http://codeforces.com/contest/508/problem/B [题意] 给你一个奇数; 让你交换一次数字; 使得这个数字变成偶数; 要求偶数要最大; [题解] ...

  8. 【codeforces 785E】Anton and Permutation

    [题目链接]:http://codeforces.com/problemset/problem/785/E [题意] 给你一个初始序列1..n顺序 然后每次让你交换任意两个位置上面的数字; 让你实时输 ...

  9. 【codeforces 785D】Anton and School - 2

    [题目链接]:http://codeforces.com/contest/785/problem/D [题意] 给你一个长度为n的括号序列; 让你删掉若干个括号之后,整个序列变成前x个括号为左括号,后 ...

随机推荐

  1. 洛谷 P2693 [USACO1.3]号码锁 Combination Lock

    P2693 [USACO1.3]号码锁 Combination Lock 题目描述 农夫约翰的奶牛不停地从他的农场中逃出来,导致了很多损害.为了防止它们再逃出来,他买了一只很大的号码锁以防止奶牛们打开 ...

  2. [Angular] HttpParams

    It is possible to use HttpParams to set http params. For example we have this url to make: https://a ...

  3. asp.net mvc 中的自定义验证(Custom Validation Attribute)

    前言

  4. Altium Designer中敷铜和板子一样大

  5. Altium Designer布局移动原件的问题

  6. sql sever 跨库查询

    reconfigure reconfigure select * from openrowset( 'SQLOLEDB', '192.168.1.180'; 'sa'; '123.com',joybl ...

  7. 8、for 、emumrate、range、if

    1.for循环用户按照顺序循环可迭代对象中的内容,PS:break.continueli = [11,22,33,44]for item in li: print item 2.enumrate 为可 ...

  8. 苹果手机wifi代理设置方法--用于抓包

    杯具了!@@@@@@@变态的公司不能直接上网了,但是经过我的研究.可以用代理上网,电脑是可以了,但是的iphone肿么办,哇咔咔,不要捉急,我来告诉你怎么让你的iphone通过代理上网.动起来吧. 请 ...

  9. SQL Server 中计算农历

    1.建一表,放初始化资料   因为农历的日期,是由天文学家推算出来的,到现在只有到2049年的,以后的有了还可以加入!   CREATE TABLE SolarData ( yearId int no ...

  10. [React Intl] Render Content with Markup Using react-intl FormattedHTMLMessage

    In this lesson, we’ll use the react-intl FormattedHTMLMessage component to display text with dynamic ...