题意:已知F0 = 0,F1 = 1,Fn = Fn - 1 + Fn - 2(n >= 2), 且若n=Fa1+Fa2+...+Fak where 0≤a1≤a2≤⋯≤a,n为正数,则n为mjf-good,否则为mjf-bad,给定k,求最小的mjf-bad. 分析:找规律可得,F2*k+3 - 1,矩阵快速幂即可. #include<cstdio> #include<cstring> #include<cstdlib> #include<cctype&g…
Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 187893    Accepted Submission(s): 46820 Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A…
题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=6030 Problem Description Little Q wants to buy a necklace for his girlfriend. Necklaces are single strings composed of multiple red and blue beads. Little Q desperately wants to impress his girlfriend,…
题目链接 Problem Description Function Fx,ysatisfies: For given integers N and M,calculate Fm,1 modulo 1e9+7. Input There is one integer T in the first line. The next T lines,each line includes two integers N and M . 1<=T<=10000,1<=N,M<2^63. Output…
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=3292 No more tricks, Mr Nanguo Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 587    Accepted Submission(s): 400 Problem Description Now Sailormoon…
GTY's birthday gift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)  [Problem Description] FFZ's birthday is coming. GTY wants to give a gift to ZZF. He asked his gay friends what he should give to ZZF. One of them…
Queuing Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6639    Accepted Submission(s): 2913 Problem Description Queues and Priority Queues are data structures which are known to most computer…
Problem of Precision Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1375    Accepted Submission(s): 826 Problem Description Input The first line of input gives the number of cases, T. T test ca…
http://acm.hdu.edu.cn/showproblem.php?pid=2855 化简这个公式,多写出几组就会发现规律 d[n]=F[2*n] 后面的任务就是矩阵快速幂拍一个斐波那契模板出来了 这里用的是2维 vector #include<iostream> #include<cstdio> #include<vector> using namespace std; typedef vector<int>vec; typedef vector&…
http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:给出 a,b,n,递推出 f(n) = f(n-1) + f(n-2) * 2 + n ^ 4. f(1) = a, f(2) = b. 思路:在比赛时候知道是矩阵快速幂,可是推不出矩阵.那个n^4不知道怎么解决.结束后问其他人才知道要构造一个7 * 7的矩阵,而不是3 * 3的.. 转自:http://blog.csdn.net/spring371327/article/details/5297…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4965 题意 给出两个矩阵 一个A: n * k 一个B: k * n C = A * B M = (A * B) ^ (n * n) 然后将M中所有的元素对6取余后求和 思路 矩阵结合律.. M = (A * B) * (A * B) * (A * B) * (A * B) * (A * B) * (A * B) * (A * B) * (A * B) -- 其实也等价于 M = A * (B *…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4565 题目大意: 给出a,b,n,m,求出的值, 解题思路: 因为题目中出现了开根号,和向上取整后求余,所以用矩阵快速幂加速求解过程的时候,会产生误差,就很自然地想到了凑数,因为(a-1)^2<b<a^2,得出0<a-sqrt(b)<1,则无论n取多大,(a-sqrt(b))^n都是小于1的,(a-sqrt(b))^n 与 (a+sqrt(b))^n共轭,两者展开后会相互抵销,所以(…
题目要求求出(√2+√3)2n的整数部分再mod 1024. (√2+√3)2n=(5+2√6)n 如果直接计算,用double存值,当n很大的时候,精度损失会变大,无法得到想要的结果. 我们发现(5+2√6)n+(5-2√6)n是一个整数(2√6的偶数次幂总会正负抵消掉),并且(5-2√6)n是小于1的.所以我们就只需要求出Sn-1即可.令 An=(5+2√6)n;  Bn=(5-2√6)n. Sn=An+Bn     Sn为整数. Sn*((5+2√6)+(5-2√6))=Sn*10 Sn*…
题意:略 简单的矩阵快速幂就行了 #include <iostream> #include <cstdio> #include <cstring> using namespace std; #define LL long long #define N 10 int m; struct node{ int mat[N][N]; node operator *(const node &x){ node tmp; memset(tmp.mat,0,sizeof(tmp…
题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a_5&a_6&a_7&a_8&a_9\\ 1&0&0&0&0&0&0&0&0&0\\ 0&1&0&0&0&0&0&0&0&0\\ 0&…
M斐波那契数列 Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status Description M斐波那契数列F[n]是一种整数数列,它的定义如下: F[0] = a F[1] = b F[n] = F[n-1] * F[n-2] ( n > 1 ) 现在给出a, b, n,你能求出F[n]的值吗?   Input 输入包含多组测试数据: 每组数据占一行,包含3个整数a…
链接:传送门 题意:求式子的值,并向下取整 思路: 然后使用矩阵快速幂进行求解 balabala:这道题主要是怎么将目标公式进行化简,化简到一个可以使用现有知识进行解决的一个过程!菜的扣脚...... 还是蒟蒻 /************************************************************************* > File Name: hdu2256.cpp > Author: WArobot > Blog: http://www.cnb…
链接:传送门 思路:简单矩阵快速幂,算完 A^k 后再求一遍主对角线上的和取个模 /************************************************************************* > File Name: hdu1575.cpp > Author: WArobot > Blog: http://www.cnblogs.com/WArobot/ > Created Time: 2017年05月02日 星期二 20时42分37秒 **…
Giving the N, can you tell me the answer of F(N)? Input Each test case contains a single integer N(1<=N<=10^9). The input is terminated by a set starting with N = 0. This set should not be processed. Output For each test case, output on a line the v…
题目链接 n个灯围成一圈, 1左边是n. 有两种状态, 1是亮, 0是不亮. 如果一个灯, 它左边的灯是亮的, 那么下一时刻这个灯就要改变状态, 1变为0, 0变为1. 给出初始状态和时间t, 问t时刻每个灯的状态是什么. ai = (a(i-1)+ai)%2, 根据这个构建矩阵. /* 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0…
题意:n个人站成一排,每个人任意从1——m中任意取一个数,要求相邻两个人的如果数字相同,数字要大于k. 分划思想推导表达式: 假设  i  个人时.第i个人的选择有两种一种是选择小于等于k的数,另一种是大于k的数.则设这两种情况的组合数分别为F(i)和 G(i) 那么F(i)=(m-k)(F(i-1)+G(i-1)):m-k表示第i个人,选择了大于k的选择. 那么G(i)=kF(i-1)+(k-1)G(i-1):  k*F(i-1),表示第i个人选的是大于k的数,而第i个人只能在0—k种选择,所…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2157 题解: 给你一个有向图,n个节点m条边,问你从i到j共经过k个节点的方法数(不算i点). 题解: 先用邻接矩阵存图. 假设k = 2,那么从i到j的方法数 = ∑ way[i][x] * way[x][j] (0<=x<n && x!=i && x!=j) 诶?快看,那是矩阵乘法! 设邻接矩阵为A,若i到j有边则val[i][j] = 1. k = 2时答案矩…
Problem Description An Arc of Dream is a curve defined by following function: where a0 = A0 ai = ai-*AX+AY b0 = B0 bi = bi-*BX+BY What ,,,?   Input There are multiple test cases. Process to the End of File. Each test nonnegative integers as follows:…
题目 春天到了, HDU校园里开满了花, 姹紫嫣红, 非常美丽. 葱头是个爱花的人, 看着校花校草竞相开放, 漫步校园, 心情也变得舒畅. 为了多看看这迷人的校园, 葱头决定, 每次上课都走不同的路线去教室, 但是由于时间问题, 每次只能经过k个地方, 比方说, 这次葱头决定经过2个地方, 那他可以先去问鼎广场看看喷泉, 再去教室, 也可以先到体育场跑几圈, 再到教室. 他非常想知道, 从A点恰好经过k个点到达B点的方案数, 当然这个数有可能非常大, 所以你只要输出它模上1000的余数就可以了.…
参考了某大佬的 我们可以根据(s[n-2], a[n-1]^2, a[n-1]*a[n-2], a[n-2]^2) * A = (s[n-1], a[n]^2, a[n]*a[n-1], a[n-1]^2) 能够求出关系矩阵 |1     0      0     0 |A =   |1   x^2    x     1 |        |0  2*x*y  y     0 |        |0   y^2    0     0 | 这样就A了! #include <iostream> #…
Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 419    Accepted Submission(s): 148 Problem Description An Arc of Dream is a curve defined by following function:wherea0 = A0ai = ai-1…
Problem Description A sequence Sn is defined as:Where a, b, n, m are positive integers.┌x┐is the ceil of x. For example, ┌3.14┐=4. You are to calculate Sn. You, a top coder, say: So easy!  Input There are several test cases, each test case in one lin…
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 99 Accepted Submission(s): 74 Problem Description A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的和),现要求Tr(A^k)%9973. Input 数据的第一行是一个T,表示有T组数据.每组数据的第一行有n(2 <= n <= 10)…
Problem Description We define a sequence F: ⋅ F0=0,F1=1;⋅ Fn=Fn−1+Fn−2 (n≥2). Give you an integer k, if a positive number n can be expressed byn=Fa1+Fa2+...+Fak where 0≤a1≤a2≤⋯≤ak, this positive number is mjf−good. Otherwise, this positive number is …
题目 第一次做是看了大牛的找规律结果,如下: //显然我看了答案,循环节点是48,但是为什么是48,据说是高手打表出来的 #include<stdio.h> int main() { ],a,b,i,n; f[]=;f[]=; while(scanf("%d%d%d",&a,&b,&n)!=EOF) { &&b==&&n==)break; ;i<;i++) { f[i]=(a*f[i-])%+(b*f[i-])%…