【codeforces 785B】Anton and Classes
and Codeforces classes
2023-09-14 09:03:47 时间
【题目链接】: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 - 557B Pasha and Tea (模拟)
- [AWS] Lab: CloudFormation and SAM to deploy a Serverless fuction
- [Kotlin] Compare Functional Programming in Java and Kotlin
- [XState] Use Internal Transitions in XState to Avoid State Exit and Re-Entry
- [Angular] Communicate with Angular Elements using Inputs and Events
- [React] Configure a React & Redux Application For Production Deployment and Deploy to Now
- [Java Spring Data] @JoinTable, @JoinColumn, joinColumns and inverseJoinColumns
- [Typescript Kaop-ts] Use AOP in Vue Components with TypeScript and Kaop-ts
- paip.Java Annotation注解的作用and 使用
- 【Codeforces Round #635 (Div. 2) C】Linova and Kingdom
- 【Codeforces Round #635 (Div. 2) B】Kana and Dragon Quest game
- 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms
- 【Henu ACM Round#14 A】Vitaly and Night
- 【Codecraft-18 and Codeforces Round #458 (Div. 1 + Div. 2, combined) C】 Travelling Salesman and Special Numbers
- 【17.00%】【codeforces 621D】Rat Kwesh and Cheese
- 【23.24%】【codeforces 629C】Famil Door and Brackets
- 【19.05%】【codeforces 680D】Bear and Tower of Cubes
- 【codeforces 764B】Timofey and cubes
- 【codeforces 750D】New Year and Fireworks
- 【codeforces 752C】Santa Claus and Robot
- 【codeforces 510B】Fox And Two Dots
- 【Codeforces Round #431 (Div. 2) A】Odds and Ends
- 【Codeforces Round #425 (Div. 2) B】Petya and Exam
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
- Python Lesson 1 :About list for if and function
- RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn
- The difference between the request time and the current time is too large.阿里云oss上传图片报错
- 【NO.3】 c program to caculate and display sum of two matrix