CCPC2019江西省賽-Problem G.Traffic

題目描述: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

相關文章
相關標籤/搜索