传送门

Avin 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

题解:

做不出这道题的童鞋相信都卡在了这个坑里。

all the cars running in the north-south direction wait the same amount of integral time so that no two cars bump.

去掉定语后是:all the cars wait the same time. 所有汽车等待时间相同。

这句话的意思是:所有南北方向上的汽车要等待相同的时间,以至于没有两辆汽车相撞。

这句话的关键是所有汽车等待时间相同,要么全都是5min,要么全都是10min,不能这辆汽车等1min、那辆汽车等2min的。

暴力枚举即可。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>using namespace std;typedef long long ll;const int maxn=1e4+10;int a[maxn],b[maxn],dis[maxn];int main()
{   int n,m;while(cin>>n>>m){memset(a,0,sizeof(a));memset(b,0,sizeof(b));memset(dis,0,sizeof(dis));for(int i=0;i<n;i++) {cin>>a[i];dis[a[i]]=1;}for(int i=0;i<m;i++) cin>>b[i];int ans;for(int i=0;i<1001;i++){int flag=0;for(int j=0;j<m;j++){if(dis[b[j]+i]){flag=1;break;}}if(!flag){ans=i;break;}}cout<<ans<<endl;}return 0;
}

Traffic (难度不够,题意来凑?)相关推荐

  1. S - Extended Traffic LightOJ - 1074

    S - Extended Traffic LightOJ - 1074 题意: 每个点有一个点权,边权为边的(终点点权-起点点权)的立方, 求从 1 出发的最短路 思路一:DJ,太简单了 结果一发WA ...

  2. DNF怎么凑异界装备(远古2)最快?

    本人玩DNF的异界已经将近一年了,相信对异界规则的理解有诸多独到之处,最近玩了一魔神,一周内凑齐了远古2装备,其中三件是套装,除了运气之外,当然需要一定的手段. 众所周知,魔神在异界可并不吃香,即使是 ...

  3. 437. Path Sum III

    题目来源: https://leetcode.com/problems/path-sum-iii/ 自我感觉难度/真实难度: 题意: 分析: 自己的代码: 这个代码,使用两次迭代循环 代码效率/结果: ...

  4. acdream 1222 Quantization Problem [dp]

    称号:acdream 1222 Quantization Problem 题意:给出一个序列 a ,然后给出一个 n * m 的矩阵,让你从这个矩阵中选出一个序列k,使得sum(abs(ki - ai ...

  5. 404. Sum of Left Leaves

    题目来源: 自我感觉难度/真实难度: 题意: 分析: 自己的代码: class Solution(object):def sumOfLeftLeaves(self, root):"" ...

  6. 653. Two Sum IV - Input is a BST

    题目来源: 自我感觉难度/真实难度: 题意: 分析: 自己的代码: class Solution(object):def findTarget(self, root, k):""& ...

  7. char* 去除后面几个字符_【算法打卡】去除重复字母

    难度:中等 题目: 给你一个字符串 s ,请你去除字符串中重复的字母,使得每个字母只出现一次.需保证 返回结果的字典序最小(要求不能打乱其他字符的相对位置). 示例 1: 输入:s = "b ...

  8. 2022.10.1 NYIST 国庆欢乐进行曲题解

    目录 A.唱!练习时长两年半的acmer练习生歌颂国庆!!! B. 跳!鸡哥想要去鸡场!!! C.rap D.篮球!妈妈我要学篮球! E.速速与董学姐击剑 F.关于比赛提前半小时封榜这件事 G. 10 ...

  9. 【编程题 】星际密码(详细注释 易懂)

    题目描述 题目链接:星际密码__牛客网      星际战争开展了100年之后,NowCoder终于破译了外星人的密码!他们的密码是一串整数,通过一张表里的信息映射成最终4位密码.表的规则是:n对应的值 ...

最新文章

  1. 通过零知识证明,成为重要的区块链革新者
  2. 产品经理做市场调研和数据分析的方法
  3. 【rabbitmq】Authentication failed (rejected by the remote node), please check the Erlang cookie
  4. Spring集成Thrift--Server AND Client
  5. 『原创』.Net CF下ListView的数据绑定
  6. LeetCode 154 在有序旋转数组中找最小-2
  7. 高精度小数 mooc 翁恺c 语言
  8. mysql 查看索引
  9. 未捕获的错误:始终违反:元素类型无效:预期为字符串(对于内置组件)或类/函数,但得到了:对象
  10. 程序员薪资怎么论高级还是初级_和程序员一样高薪,却过着清闲生活,测试员什么人都可做吗?...
  11. webstorm如何自定义代码模板
  12. zookeeper 环境搭建之(Windows上的简单部署)
  13. 《王道》数据结构笔记整理2022
  14. 基于java的志愿信息管理系统_毕业设计 基于JAVA的志愿者管理系统的设计与实现...
  15. java压缩文件夹下所有文件
  16. IOS应用程序崩溃日志分析
  17. 创建一个8*8的国际象棋棋盘(黑块为0,白块为1)
  18. kingbase8建表
  19. 微信小程序~textarea字数限制与计算
  20. TCP/IP卷一:26---Internet协议之(IPv4、IPv6数据报,Internet校验和)

热门文章

  1. win10声音图标有个❌没有声音
  2. linux服务器安装mysql数据库并通过本地Navicat连接访问远程mysq数据库
  3. android Activity转场动画makeSceneTransitionAnimation
  4. 论文笔记United adversarial learning for liver tumor segmentation
  5. 人工智能数学课高等数学线性微积分数学教程笔记(6. 概率论)
  6. 通话记录分析 --- 通话详情 之一
  7. 连接无处不在——2016年中国国际信息通信展带你叩响未来世界的大门
  8. 天天写“业务代码”,如何成为“技术大拿?
  9. 【Microsoft Whiteboard】微软白板 下载
  10. 公网如何SSH远程连接内网服务器