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[10005],b[10005];
int main()
{
    int n,m,x;
    while(cin>>n>>m)
    {
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(int i=0;i<n;i++)
        {
            cin>>x;
            a[x]=1;
        }
        for(int i=0;i<m;i++)
          cin>>b[i];
        int t=0;
        for(int i=0;i<m;i++)
        {
            if(a[b[i]+t])//如果b[i]+t==a[j]
            {           
                t++;
                i=-1;
            }
        }
        cout<<t<<endl;
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/-citywall123/p/11234432.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1 package com.alibaba.traffic.web; 2 3 import java.io.UnsupportedEncodingException; 4 import java.security.InvalidKeyException; 5 import java.security.NoSuchAlgorithmException; 6 7 import javax.crypto.Mac; 8 import javax.crypto.SecretKey; 9 import javax.crypto.spec.SecretKeySpec; 10 11 import org.apache.commons.codec.binary.Hex; 12 特别注意 附件 6 13 /** 14 * @author dongdong.fdd 15 * @date 2018/9/27 上午11:29 16 */ 17 public class T { 18 public static void main(String[] args) 19 throws InvalidKeyException, UnsupportedEncodingException, No SuchAlgorithmException { 20 long timestamp = System.currentTimeMillis() / 1000; 21 String paramValuesStr = "allAMAP-TRAFFIC-BRAIN10" + timestam p;//该值为排好序的参数的参数值拼接结果 22 String clientSecret = "testclientsecret";//该值为申请到的client Secret 23 24 Mac mac = Mac.getInstance("HmacSHA256"); 25 byte[] secretByte = clientSecret.getBytes("UTF-8"); 26 byte[] dataBytes = paramValuesStr.getBytes("UTF-8"); 27 28 SecretKey secretKey = new SecretKeySpec(secretByte,"HMACSHA2 56"); 29 mac.init(secretKey); 30 31 byte[] doFinal = mac.doFinal(dataBytes); 32 byte[] hexB = new Hex().encode(doFinal); 33 34 String digest = new String(hexB, "utf-8");//计算好的签名 26f2042cde2e9ca01d41ecdb27a91fd9b84f0263c411bcb13b195ec589096885 35 System.out.println(digest); 36 37 String resultUrl = "http://et-api.amap.com/index/cityRankin g?adcodes=all&clientKey=AMAP-TRAFFIC-BRAIN&size=10&timestamp="+times tamp+"&digest=" + digest; 38 System.out.println(resultUrl); 39 } 将这段代码使用python实现
最新发布
07-14

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值