G - Traffic
vin is observing the cars at a crossroads. He finds that there are n cars running in the east-west direction with the i-th car passing the intersection at time ai . There are another m cars running in the north-south direction with the i-th car passing the intersection at time bi . If two cars passing the intersections at the same time, a traffic crash occurs. In order to achieve world peace and harmony, all the cars running in the north-south direction wait the same amount of integral time so that no two cars bump. You are asked the minimum waiting time.
input
The first line contains two integers n and m (1 ≤ n, m ≤ 1, 000). The second line contains n distinct integers ai (1 ≤ ai ≤ 1, 000). The third line contains m distinct integers bi (1 ≤ bi ≤ 1, 000).
output
Print a non-negative integer denoting the minimum waiting time.
Sample Input
1 1
1
1
1 2
2
1 3 Sample Output
1
0 题意:n辆车从一边经过十字路口,m辆车从另一边经过十字路口,当n方向的车经过路口时,m方向的车必须停下等待。给定车辆经过路口的时间,问m方向的车最少要等多久 题解:假设等待时间时t,当两个方向 的车同时经过路口时需要等,即b[j]+t==a[i],枚举输出最大的t即可
#include<iostream>
#include<string.h>
using namespace std;
int a[],b[];
int main()
{
int n,m,x;
while(cin>>n>>m)
{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(int i=;i<n;i++)
{
cin>>x;
a[x]=;
}
for(int i=;i<m;i++)
cin>>b[i];
int t=;
for(int i=;i<m;i++)
{
if(a[b[i]+t])//如果b[i]+t==a[j]
{
t++;
i=-;
}
}
cout<<t<<endl;
}
return ;
}
G - Traffic的更多相关文章
- zoj 4020 The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light(广搜)
题目链接:The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light 题解: 题意 ...
- CCPC2019江西省赛-Problem G.Traffic
题目描述: /*纯手打题面*/ Avin is observing the cars at a crossroads.He finds that there are n cars running in ...
- 152 - - G Traffic Light 搜索(The 18th Zhejiang University Programming Contest Sponsored by TuSimple )
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5738 题意 给你一个map 每个格子里有一个红绿灯,用0,1表示 ...
- Complexity and Tractability (3.44) - The Traveling Salesman Problem
Copied From:http://csfieldguide.org.nz/en/curriculum-guides/ncea/level-3/complexity-tractability-TSP ...
- Reading SBAR SDN flow-Based monitoring and Application Recognition
概要 在sdn下,控制平面基于网络测量的的数据控制网络,而细粒度的管理得益于细粒度的测量数据.针对sdn环境下的细粒度测量(识别具体应用程序),可以实现对细粒度的流量管控. 设计了识别系统SBAR,对 ...
- QDU_组队训练(AJFC)
A - Pretty Matrix DreamGrid's birthday is coming. As his best friend, BaoBao is going to prepare a g ...
- <JAVA图像学习笔记>十字路口交通模拟--操作系统模拟课后小项目
项目的要求很简单: 模拟出十字路口的交通控制情况: 秒. 当东西(或南北)方向红灯时,所有车辆(除了消防车.救护车.警车)均排队等待,当东西(或南北)方向绿灯时,所有车辆按序行驶(不准超车). 制作这 ...
- Smart internet of things services
A method and apparatus enable Internet of Things (IoT) services based on a SMART IoT architecture by ...
- Network management system scheduling for low power and lossy networks
In one embodiment, a network management system (NMS) determines an intent to initialize a request-re ...
随机推荐
- python字典中值为列表或字典的构造方式
1.值为列表的构造方法 dic = {} dic.setdefault(key,[]).append(value) >>dic.setdefault('a',[]).append(1) & ...
- 学习笔记(14)- SQuAD的数据格式
BERT模型完成问答任务的时候,需要数据格式为SQuAD形式. 有2个版本,1.1和2.0
- 51nod 1449:砝码称重
1449 砝码称重 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 收藏 取消关注 现在有好多种砝码,他们的重量是 w0,w1 ...
- ch8 让div居中--使用外边距
假设有一个布局,希望让其中的容器div在屏幕上水平居中,则只需要定义div的宽度,然后将水平外边距设置为auto <body> <div class="wrapper&qu ...
- CSS文本居中显示
因为一直为元素居中问题而困扰,所以决定把自己遇到和看到的方法记录下来,以便以后查看 如果要让inline或inline-block元素居中显示,则父元素css中包含text-align:center; ...
- SVN提交失败:Changing file 'XXX' is forbidden by the server;Access to 'XXX' forbidden
解决方案:https://blog.csdn.net/m0_38084243/article/details/81503638 个人分析主要是后者,在SVN服务器上添加上我对本项目的读写权限即可: 添 ...
- pycharm不能安装第三方库,错误代码Non-zero exit code (1) 的解决办法
pycharm版本 2019.3 大致意思是安装失败,建议的解决方案:尝试从系统终端运行此命令.确保使用正确的'pip'版本,该版本已为位于'C:\ Users \ G \ Desktoplgianf ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:制作一个大按钮
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Day2-G-Sticks-POJ1011
George took sticks of the same length and cut them randomly until all parts became at most 50 units ...
- linux--redis学习
redis redis在linux的安装 1.redis安装方式 yum安装(提前配置好yum源) yum install redis -y # 源代码编译安装 rpm包手动安装 2.编译安装redi ...