codeforce Anton and Classes
来源:互联网 发布:ios同步请求数据 编辑:程序博客网 时间:2024/05/16 15:18
题意:给你两个线段集合A,B,求它们之间的最大距离。距离的定义为:如果相交,则为0。否则,为: 右边线段的L-左边线段的R.
所以最大距离 为:A.L(max) - B.R(min) or B.L(max) - A.R(min);
#include <bits\stdc++.h>using namespace std;struct point{ int l; int r;};struct point a1[200005],a2[200005]; int dista(struct point a, struct point b){ if(a.l > b.l) swap(a,b); if(a.r >= b.l) return 0; else return fabs((b.l - a.r));}int main(){ int n,m; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d%d",&a1[i].l,&a1[i].r); } scanf("%d",&m); for(int i=0;i<m;i++){ scanf("%d%d",&a2[i].l,&a2[i].r); } struct point minr = a1[0],maxl=a1[0]; for(int i=1;i<n;i++){ if(a1[i].r < minr.r) minr = a1[i]; if(a1[i].l > maxl.l) maxl = a1[i]; } struct point minrr = a2[0],maxll=a2[0]; for(int i=1;i<m;i++){ if(a2[i].r < minrr.r) minrr = a2[i]; if(a2[i].l > maxll.l) maxll = a2[i]; } int dis1 = dista(minr,maxll); int dis2 = dista(minrr,maxl); printf("%d\n",max(dis1,dis2)); return 0;}
0 0
- codeforce Anton and Classes
- Anton and Classes
- B. Anton and Classes
- B. Anton and Classes
- B. Anton and Classes
- codeforce Anton and Fairy Tale
- codeforce #329div2 B. Anton and Lines
- CodeForce-734C Anton and Making Potions
- 【codeforces 785B】Anton and Classes
- Codeforces Round#404 B. Anton and Classes
- Codeforces 785B-Anton and Classes
- CodeForces 785B Anton and Classes【水题】
- Codeforces 785B Anton and Classes(贪心)
- Codeforce 734C Anton and Making Potions 枚举+二分
- Codeforce#379C. Anton and Making Potions(二分or贪心)
- 【CodeForce 734C 】Anton and Making Potions (枚举+二分)
- codeforce 785 C.Anton and Fairy Tale(二分)
- Codeforces Round #404 (Div. 2) B. Anton and Classes
- Spring事务管理(详解+实例)
- 关于Metasploit的学习笔记(二)
- [bzoj3492]Binary Dodgeball
- java基础复习之网络编程了解篇 十四 -1
- ZigBee广播通信原理及ZigBee网络的一些特性
- codeforce Anton and Classes
- IT教程视频合集 编程教程视频合集 8000G分享
- 判断一棵树为另一颗树的子树
- 炼数成金《机器学习》系列00
- 手把手教你使用Git
- L2-007. 家庭房产
- 【转载】透视“专利恶霸”系列之二 蜕变后的苹果有了新玩法
- CUDA总结:线程网络和线程分配
- run "setprop ctrl.start wpa_supplicant" manually