题目描述:html
/*纯手打题面*/
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 a[i].There are another m cars running in the north-south direction with the i-th car passing the intersection at time b[i].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 time amount of integral time so that no two cars bump.You are asked the
minimum waiting time.
/*纯手打题面*/
Input数组
n m a[i] b[i] (1<=n,m<=1000;1<=ai,bi<=1000)
Output优化
The minimum waiting time(integer).
题解心得:ssr
啊啊啊啊啊啊啊啊啊啊啊啊,当时在比赛的时候翻了很久词典,终于把这个题目的意思大概搞懂了code
而后和咱们队的大佬讨论了很久htm
一开始爆搜O(N3)blog
而后想了很久奇奇怪怪的方法,分治什么的,而后就剪枝优化。it
可是最后用标记法把时间复杂度压到了O(N2)。io
大体思路:ast
枚举时间(一个循环)
在每一个循环里标记a[i]所占的时间点(布尔数组c)
同时标记b[i]+t的时间点(布尔数组d)
接着c&&d;
就能够了。
这题真的水,不加剪枝也能AC。
代码:
之后附。
原文出处:https://www.cnblogs.com/XYYXP/p/JXCPC_2019_Problem_G.html