[原创]玲珑 OJ 1109 Niro plays with snow [递推 + 预处理矩阵乘法]【数学】
2017-03-20 13:37:14 Tabris_ 阅读数:296
博客爬取于 2020-06-14 22:41:10
以下为正文
版权声明:本文为 Tabris 原创文章,未经博主允许不得私自转载。
https://blog.csdn.net/qq_33184171/article/details/64124556
题目链接:http://www.ifrog.cc/acm/problem/1109
————————————————————————————————————————————
1109 - Niro plays with snow
Time Limit:2s Memory Limit:128MByte
Submissions:50Solved:8
DESCRIPTION
Ah, it snows.
Niro picks up a snowflake. It grows every second. At every second, each of the smallest triangles splits and one of the two rotates by 180 degrees. The process is shown below. In the picture, blue represents the areas that are one layer thick, red two layers thick, yellow three layers thick, and green four layers thick.

Now let F(n) be the number of smallest triangles that are one layers thick at order n, and G(n) be the number of smallest triangles thar are three layers thick at order n. For example, F(1) = 1, G(1) = 0, F(2) = 6, G(2) = 0, F(3) = 30, G(3) = 6, F(4) = 138, G(4) = 78.
Given n, can you tell Niro F(n) and G(n) modulo 1234321237?
INPUT
T+1 lines.
The first line contains one integer T, the number of test cases.
Each of the following T lines contains one integer n.
OUTPUT
T lines.
Each line contains two integers, F(n) \mod 1234321237 and G(n) \mod 1234321237 for each query.
SAMPLE INPUT
5
3
4
5
52
100
SAMPLE OUTPUT
30 6
138 78
606 654
540534048 39147304
978578590 88026038
HINT
$1≤T≤10^5 $1≤n≤10^18
————————————————————————————————————————————
题目大意:
就是问你 第 n 个图形中 一层 和三层的三角形有多少个
解题思路:
看了看数据范围,想到是个矩阵乘法,也推出了 $8*8的矩阵乘法 \left[\begin{array}{cc}\ 0&&6&&0&&0&&0&&0&&0&&0 \0&&3&&2&&0&&1&&0&&0&&0 \0&&1&&2&&1&&2&&0&&0&&0 \0&&0&&0&&3&&3&&0&&0&&0 \0&&0&&0&&0&&0&&6&&0&&0 \0&&0&&0&&0&&0&&3&&2&&0 \0&&0&&0&&0&&0&&1&&2&&1 \0&&0&&0&&0&&0&&0&&0&&3 \\end{array}\right]\times \left[\begin{array}{cc} F_0(i)\F_1(i)\F_2(i)\F_3(i)\G_0(i)\G_1(i)\G_2(i)\G_3(i)\ \end{array}\right] = \left[\begin{array}{cc} F_0(i+1)\F_1(i+1)\F_2(i+1)\F_3(i+1)\G_0(i+1)\G_1(i+1)\G_2(i+1)\G_3(i+1) \end{array}\right]$
-其中F_i()表示三角形三边中有i条变邻近红色(两层)
-其中G_i()表示三角形三边中有i条变邻近红色(两层)
然而交上去就 TLE 了,,,,
复杂度O(T\times \log_2^{3}(n)) .....
然后听了 Q 的说法 预处理出所有的 A 矩阵的 $2^i次幂 然后在计算的时候只要用向量乘上矩阵就好了 复杂度就变成了O(T\times \log_2^{2}(n))$ 然后就过了
然而当时听说还有用 4*4 的矩阵过得..
最后看了题解 ,真是玄妙无比啊..有兴趣的戳一下题解的传送阵
附本题代码
————————————————————————————————————————————
1 | # include <bits/stdc++.h> |


