我在清华姚班学「考古」
HZOI 帝国纳新
干货:
- 将一个 (DAG) 连边成强联通,最少需要的边的个数为:出度为 (0) 的点的个数和入度为 (0) 的点的个数的最大值,即 (max(sum_{i=1}^{n}[cdeg[i]=0],sum_{i=1}^{n}[rdeg[i]=0]))
HZOI 帝国布线
小技巧:
- 在一个平面直角坐标系中,给定一个矩阵上的三个点,如何求出第四个点?
会有一个特殊情况:
震惊!矩形是斜着的,那咋得求咧?
假设这三个点分别为 (node_1, node_2, node_3),有它们的坐标,我们就可以确定三个点分别的距离:(dis_{1,2},dis_{2,3},dis_{1,3}),用下小学学的勾股定理,我们就可以确定直角顶点:
-
若直角顶点为 (node_1),(x_4=x_2+x_3-x_1,y_4=y_2+y_3-y_1);
-
若直角顶点为 (node_2),(x_4=x_1+x_3-x_2,y_4=y_1+y_3-y_2);
-
若直角顶点为 (node_3),(x_4=x_1+x_2-x_3,y_4=y_1+y_2-y_3);
inline int Tmp (register Node a, register Node b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
inline Node Getnode (register int x1, register int y1, register int x2, register int y2, register int x3, register int y3) {
register int x4 = 0, y4 = 0;
register Node tmp1 = Node (x1, y1), tmp2 = Node (x2, y2), tmp3 = Node (x3, y3);
register double len1 = Tmp (tmp1, tmp2);
register double len2 = Tmp (tmp2, tmp3);
register double len3 = Tmp (tmp1, tmp3);
if (len1 + len3 == len2) x4 = x2 + x3 - x1, y4 = y2 + y3 - y1;
else if (len1 + len2 == len3) x4 = x1 + x3 - x2, y4 = y1 + y3 - y2;
else if (len2 + len3 == len1) x4 = x1 + x2 - x3, y4 = y1 + y2 - y3;
return Node (x4, y4);
}