Kick Start 2018

1. Planet Distance

Q:有很多星球,在每个星期之间会有管道,当这些管道和星球形成环的时候,这些形成环的星球上会有一些礼物,这些形成环的星球离礼物的距离为0,其它星球离礼物的距离,是到形成环的所有星球中距离最短的那条,求所有星球到礼物的距离。
A:有环无向图上的所有节点距离环的最短距离, 可以先用DFS/拓扑排序找到环上的点,然后去BFS去求每个节点到环上的距离。

3. Kickstart Alarm

Q:有点难理解,直接用例子貌似好一点
if i = 2, and A = [1, 4, 2], then the i-th exponential-power of A would be calculated as follows:

  • 2-nd exponential-power of [1] = 1 × 1^2 = 1
  • 2-nd exponential-power of [4] = 4 × 1^2 = 4
  • 2-nd exponential-power of [2] = 2 × 1^2 = 2
  • 2-nd exponential-power of [1, 4] = 1 × 1^2 + 4 × 2^2 = 17
  • 2-nd exponential-power of [4, 2] = 4 × 1^2 + 2 × 2^2 = 12
  • 2-nd exponential-power of [1, 4, 2] = 1 × 1^2 + 4 × 2^2 + 2 × 3^2 = 35

so the total is 71.

A:
数学题,通过整理可以得出:$$Answer = sum_{i=1}^nsum_{j=1}^isum_{l=1}^kA_i*(n-i+1)*j^l$$
整理一下$$p_i=sum_{j=1}^ki^j,s_i=sum_{j=1}^ip_i$$ $$Answer = sum_{j=1}^nA_i*(n-i+1)*s_i$$
可以用快速幂做

原文地址:https://www.cnblogs.com/xym4869/p/13236050.html