挑战8:存储车运输计划!


10

<<上一页

感谢PPCG社区,圣诞老人现在已经平衡了他的储物车。现在,他需要将它们移入运输码头,以便可以将它们发送到装卸区。不幸的是,用来移动推车的轨道是一团糟,他需要弄清楚如何使它们四处走动而不会撞在一起!

挑战

您将获得每个推车的轨道,作为“标签”(或车站)列表。必须移动推车,以便在任何时间框架内,没有两个推车位于同一标签/站上。本质上,手推车在每个都有唯一标签的位置之间移动。

任务

给定每个购物车的轨道作为标签列表的列表(均为正整数),请确定何时应释放每个购物车,以便在尽可能短的时间内安全地将所有购物车发送到目的地。

这是整个轨道系统如何工作的解释。假设购物车i有时被t_i放到带有标签的轨道上T_i_1, T_i_2, ..., T_i_n。然后,在t_1t_i-1,车i不上格,可以忽略。

在时间范围内t_i,购物车在标签上T_i_1,对于t_kt_i到的每个时间范围t_i+n(包括半值),购物车都在标签上T_i_k+1

对于之后的所有时间范围(包括之后)t_i+n,购物车都位于其目的地,并且不再位于网格上。

所花费的总时间t_T是系统中轨道仍在推车上的最后时间范围。

技术指标

给出的轨道系统,返回时间帧的列表[t_1, t_2, ..., t_n],其中i个车开始在时间t_i,使得没有其他的安排将使车安全地到达目的地,随着时间较少总量。

在“安全”方面,如果在任何时间框架t_1,以t_T有任何标签上超过一个购物车,然后他们碰撞和安排是不“安全”。请注意,两个手推车可以从a, b移到b, a,但仍然是“安全的”,因为轨道是双向的。

格式化规格

输入将以任何合理格式的正整数矩阵形式给出。输出应以任何合理格式的正整数列表形式给出。您可以在零索引的时间范围内提供输出,因此输出将是任何合理格式的非负整数列表。

规则

  • 适用标准漏洞
  • 这是一个所以最短答案以字节为单位
  • 没有答案将被接受

测试用例

Input -> Output
[[1, 2, 3], [4, 5, 6], [7, 8, 9]] -> [1, 1, 1]
[[1, 2, 3], [1, 2, 3]] -> [1, 2]
[[1, 2, 3], [3, 2, 1]] -> [1, 2]
[[1, 2, 3, 4], [4, 3, 2, 1]] -> [1, 1]
[[1, 1, 1], [1, 1, 1]] -> [1, 4]
[[1, 2, 3, 4], [2, 4, 3, 1]] -> [2, 1]
[[1, 2, 3, 4, 5, 6, 7], [2, 3, 3, 4], [5, 4, 3]] -> [1, 3, 4]
[[1, 2, 3, 4, 4], [1, 2, 3, 5, 4], [1, 2, 3, 4, 5]] -> [2, 3, 1]

注意:我从Advent Of Code中汲取了灵感,来挑战这个系列。我没有与此网站的隶属关系

通过在此处查看第一个挑战的“链接”部分,可以查看该系列中所有挑战的列表。

高尔夫快乐!


不了解要求:购物车=数组?
l4m2

得到:in [i] [t-out [i]]对于任何t都不同,并且最大的out [i] + in.length最小,如果我正确地猜想样本
l4m2

@ l4m2您对什么感到困惑?我想我已经足够清楚了规格...该数组代表每个购物车采用的路径
HyperNeutrino

我没有仔细阅读文本(对我来说太难读了,也许是我的错),并认为它是2D板
l4m2

Answers:


4

JavaScript(ES7),172个字节

返回索引为0的时间范围的数组。

a=>(g=k=>a.map((a,i)=>[l=a.length+1,i,a,L=L<l?l:L]).sort(([a],[b])=>a-b).every(([,n,b],i)=>b.every((c,t)=>o[t+=A[n]=k/L**i%L|0]&1<<c?0:o[t]|=1<<c),o=[],A=[])?A:g(k+1))(L=0)

注意:这仅适用于[0-31]中的标签。这是JS限制,而不是算法限制。

测试用例

已评论

a => (                         // given a = array of tracks
  g = k =>                     // g = recursive function taking k = counter
    a.map((t, i) => [          // map each track t in a to a new entry made of:
      l = t.length + 1,        //   - its length + 1 (l)
      i,                       //   - its original index in the input array
      t,                       //   - the original track data
      L = L < l ? l : L        //   and update the maximum track length L
    ])                         // end of map()
    .sort(([a], [b]) =>        // let's sort the tracks from shortest to longest
      a - b                    // so that solutions that attempt to delay short
    )                          // tracks are tried first
    .every(([, n, b],          // for each track b with an original position n,
                      i) =>    // now appearing at position i:
      b.every((c, t) =>        //   for each label c at position t in b:
        o[t += A[n] =          //     add to t the time frame A[n] corresponding
          k / L**i % L | 0     //     to this position (i) and this combination (k)
        ] & 1 << c ?           //     if the station c is already occupied at time t:
          0                    //       make every() fail
        :                      //     else:
          o[t] |= 1 << c       //       mark the station c as occupied at time t
      ),                       //   end of inner every()
      o = [],                  //   start with: o = empty array (station bitmasks)
      A = []                   //               A = empty array (time frames)
    ) ?                        // end of outer every(); if successful:
      A                        //   return A
    :                          // else:
      g(k + 1)                 //   try the next combination
)(L = 0)                       // initial call to g() + initialization of L

我想是因为按位运算符?(<<|)可以通过使用布尔数组代替来解决...
user202729

@ user202729是的,这是因为对存储在中的值进行了按位运算符o[]。(确实可以做不同的事情,但是我首先选择这种方法是为了高尔夫球手的结果。)
Arnauld
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.