水题(令人费解)

G - Traffic

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.

InputThe 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).OutputPrint 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 car waite the same time。自认为是可以一个个的插入。

主要是理解题意
暴力即可。。。
#include <vector>
#include <iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include <stdio.h>
#include <string.h>

using namespace std;
int w[2009] ,s[2009];
int vis[2009];



int main()
{
    int e , n ;
    while(~scanf("%d%d" , &e,&n))
    {
        memset(vis , 0 , sizeof(vis));
        for(int i = 0 ; i < e ; i++)
        {
            scanf("%d" , &w[i]);
        }
        for(int i = 0 ; i < n ; i++)
            scanf("%d" , &s[i]);
        int t = 0 ;
        for(int i = 0 ; i < n ; i++)
        {
            for(int j = 0 ; j < e ; j++)
            {
                if(s[i] + t == w[j])
                {
                    t ++ ;
                    i = -1 ;
                    break ;
                }
            }
        }
        printf("%d\n" , t);
    }

    return 0;
}
 

猜你喜欢

转载自www.cnblogs.com/nonames/p/11252242.html
今日推荐