RE:ゼロから始める PKU 生活 episode 3
yyb说,我已经15个月没有更过博了。
事实上,去年11月我发过一篇 RE:ゼロから始める PKU 生活 episode 2,只不过被我隐藏掉了。所以应该只有一年没有更博。
这一年里经历了一些事情。我肯定是无意写在这里的,这里是博客,又不是可以随便倒垃圾的pyq。不过好在已经结束了,就当是经历了一场历练吧。
是时候从零开始了。
11.6 关于写题解的重要性
“有人相爱,有人夜里看海,有人ddl前一天量子作业写不出来。”
写一下一个月前的一道信数作业题。貌似是在从南宁回来的飞机上想出来的,当时也是ddl前一天。
那道题是这样的:在\(d = 1000\)维空间里生成尽可能多的单位向量,使得任意两个向量的夹角在\([85^{\circ}, 95^{\circ}]\)之间。
我听说周队长用梯度下降跑的,他说\(80000+\)随便跑。我连\(1000\)个都没法用随机方法生成出来。
当时本来都打算直接交\(1000\)作为结果摆烂的,结果突然回想起一道OI题 2018 Multi-University Training Contest 2: Hack It,大概的题意是需要构造一个 \(n \times n(n \le 2000)\) 的 \(01\) 矩阵,满足其中 \(1\) 的个数不少于 \(85000\) 个,同时矩阵的任意两行 \(1\) 的位置的交集大小不超过 \(1\)。
这个题甚至在这里写过题解。
参考那道题的做法后好像就会做了。下面是从当时的作业里抄出来的:
The inner product of two vectors equals to the angle between them multiplied by the lengths of these two vectors. Since they are both unit vectors, the fact that the angle between two random unit vectors is from \(85^\circ\) to \(95^\circ\) is equivalent to that the inner product between them is from \(-\sin\frac{\pi}{36}\) to \(\sin\frac{\pi}{36}\). Let \(\delta = \sin\frac{\pi}{36}\) for convenience.
I find it(指那道 OI 题) the exactly solution I am looking for, so here it goes:
- find a prime number \(p\) where \(p^2 \le d\).
- generate \(k\) unit vectors in \(p\)-dimension satisfying any two vectors have inner product less than \(\delta\), and the absolute value of the coordinate on each dimension does not exceed \(\sqrt \delta\). This is not difficult since \(\sqrt{\delta} \approx 0.2952\) which is not too small.
- Construct \(kp^2\) vectors in \(p^2\)-dimension. The \((xp^2 + yp + z)\)-th vector among them\((0 \le x < k, 0 \le y, z < p)\) is extended from the \(x\)-th vector generated in \(p\)-dimension, with the coordinate on \(t\)-th of \(p\)-dimension corresponding to \([pt + (yt+z \bmod p)]\)-th of \(p^2\)-dimension. All other coordinate in \(p^2\)-dimension are set to be \(0\), and clearly these constructed vectors are all unit vectors.
It can be proved (will be shown later) that for any two vectors, the absolute value of inner product does not exceed \(\delta\), so the constraint is met.
For \(d = 1000\), we can pick \(p = 31\) since it's a prime number and \(p^2 = 961 < 1000\), and \(k = 37\) vectors (just a few) can be generated in \(p\)-dimension satisfying the constraint mentioned above. So we can actually construct a set of unit vectors with size \(kp^2 = 35557\). It is apparently a quite rough work, and lots of thing can be done to improve the result --- But TA said the full-score standard does not exceed \(30000\), so maybe I could just stop here 😃
We use a triple \((x, y, z)\) to represent the \((xp^2 + yp + z)\)-th vector. Our goal is to prove that for any \((x_1, y_1, z_1) \neq (x_2, y_2, z_2)\), the inner product between them is less than \(\delta\). First we prove that for two vectors with different \((y, z)\), they have non-zero coordinates simultaneously on at most \(1\) dimension.
- For two vectors with \((y_1, z_1) \neq (y_2, z_2)\), they have non-zero coordinates on \((ap + b)\)-th dimension iff \(ay_1 + z_1 \equiv ay_2 + z_2 \equiv b \bmod p\). So the number of dimensions these two vectors have non-zero coordinates simultaneously on is equal to the number of solutions to the congruence equation above. Since when \(p\) is prime, the equation \(a(y_1 - y_2) \equiv z_2 - z_1 \bmod p\) has one solution \((z_2 - z_1)(y_1 - y_2)^{-1} \bmod p\) when \(y_1 \neq y_2\), and has no solution when \(y_1 = y_2\) and \(z_1 \neq z_2\). So the number of solutions is at most one, and the number of dimensions is also at most one.
Thus, for any two vectors with different \((y, z)\), the inner product between them has at most one non-zero item. Since each coordinates is of absolute value not greater than \(\sqrt{\delta}\), the absolute value of inner product will not be greater than \(\delta\).
If two different vectors have the same \((y, z)\), they must differ from each other on \(x\). The inner product between vector \((x_1, y, z)\) and \((x_2, y, z)\) in \(p^2\)-dimension is exactly equal to the inner product between \(x_1\)-th and \(x_2\)-th unit vector in \(p\)-dimension, and thus is of absolute value less than \(\delta\). \(\blacksquare\)

浙公网安备 33010602011771号