題目描述: Input Output 題解心得: 啊啊啊啊啊啊啊啊啊啊啊啊,當時在比賽的時候翻了好久詞典,終於把這個題目的意思大概搞懂了 然後和我們隊的大佬討論了好久 一開始爆搜O(N3) 然後想了好久奇奇怪怪的方法,分治什麼的,然後就剪枝優化。 但是最後用標記法把時間複雜度壓到了O(N2)。 大致 ...
題目描述:
/*純手打題面*/
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).
題解心得:
啊啊啊啊啊啊啊啊啊啊啊啊,當時在比賽的時候翻了好久詞典,終於把這個題目的意思大概搞懂了
然後和我們隊的大佬討論了好久
一開始爆搜O(N3)
然後想了好久奇奇怪怪的方法,分治什麼的,然後就剪枝優化。
但是最後用標記法把時間複雜度壓到了O(N2)。
大致思路:
枚舉時間(一個迴圈)
在每個迴圈里標記a[i]所占的時間點(布爾數組c)
同時標記b[i]+t的時間點(布爾數組d)
接著c&&d;
就可以了。
這題真的水,不加剪枝也能AC。
代碼:
以後附。