题意: 通过各种操作进行,给第i只猫花生,第i只猫吃光花生,第i只猫和第j只猫互换花生,问n次循环操作后结果是什么 很明显是构建个矩阵,然后矩阵相乘就好了 #include <iostream> #include <cstdio> #include<cstring> using namespace std; #define LL long long #define N 110 LL n,m,d; struct node{ LL mat[N][N]; node opera…
题目链接 题意:有n个猫,开始的时候每个猫都没有坚果,进行k次操作,g x表示给第x个猫一个坚果,e x表示第x个猫吃掉所有坚果,s x y表示第x个猫和第y个猫交换所有坚果,将k次操作重复进行m轮,问最后这n个猫各自有多少坚果. 题解:构造(n+1)*(n+1)的单位矩阵,data[i][j]表示第i个猫与第j个猫进行交换,最后一列的前n项就是每个猫的坚果数目,s操作就交换对应行,矩阵快速幂时间复杂度O(n^3*log2(m))会超时,我们注意到在n*n的范围内每一行只有一个1,利用稀疏矩阵的…
Description Facer's pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to make the cats to do some exercises. Facer has well designed a set of moves for his cats. He is now asking you t…
Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13488   Accepted: 3335 Description Facer's pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to make t…
http://poj.org/problem?id=3735 给定一串操作,要这个操作连续执行m次后,最后剩下的值. 记矩阵T为一次操作后的值,那么T^m就是执行m次的值了.(其实这个还不太理解,但是数据一相乘,就是ans) 构造一个0--n的单位矩阵,用第0行作为各个猫的值,这样的话,用A={1,0,0,0}一乘就是每个毛的ans. 构造单位矩阵的意义就是他们矩阵自己相乘的时候,能够保留自己的值. 这个矩阵很分散,0的那些可以特判掉不枚举多一程O(n)了.这需要你的矩阵乘法是一个一个加上去的,…
Magic Bracelet Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 4990   Accepted: 1610 Description Ginny’s birthday is coming soon. Harry Potter is preparing a birthday present for his new girlfriend. The present is a magic bracelet which…
矩阵快速幂,请参照模板 http://www.cnblogs.com/pach/p/5978475.html 直接sum=A+A2+A3...+Ak这样累加肯定会超时,但是 sum=A+A2+...+Ak/2+A(k/2)*(A+A2+...+Ak/2)    k为偶数时: sum=A+A2+...+A(k-1)/2+A((k-1)/2)*(A+A2+...+A(k-1)/2)+Ak    k为奇数时. 然后递归二分求和 PS:刚开始mat定义的是__int64,于是贡献了n次TLE... #i…
设S[k] = A + A^2 +````+A^k. 设矩阵T = A[1] 0 E E 这里的E为n*n单位方阵,0为n*n方阵 令A[k] = A ^ k 矩阵B[k] = A[k+1] S[k] 则有递推式B[K] = T*B[k-1],即有B[k] = T^k*B[0],令S[0] 为n*n的0矩阵. 矩阵快速幂求出即可····· 还可以使用两次分治的方法····自行百度···· 贴代码: #include<cstdio> #include<cstring> int n,k…
!:自环也算一条路径 矩阵快速幂,把矩阵乘法的部分替换成Floyd(只用一个点扩张),这样每"乘"一次,就是经过增加一条边的最短路,用矩阵快速幂优化,然后因为边数是100级别的,所以把点hash一下最多剩下200个 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=205,inf=1e9; int n,m,s,t,g[N],…
题目描述 For their physical fitness program, N (2 ≤ N ≤ 1,000,000) cows have decided to run a relay race using the T (2 ≤ T ≤ 100) cow trails throughout the pasture. Each trail connects two different intersections (1 ≤ I1i ≤ 1,000; 1 ≤ I2i ≤ 1,000), each…