uva 1386 - Cellular Automaton(循环矩阵+矩阵快速幂)
来源:互联网 发布:xmind8 for mac序列号 编辑:程序博客网 时间:2024/05/29 09:15
题目链接:uva 1386 - Cellular Automaton
题目大意:一个细胞自动机,有n个格子,每个格子的取值为0~m-1。给定距离d,每次操作后每个格子的值将变为到它距离不超过d的所有格子在操作之前的值之和除以m的余数。
解题思路:矩阵快速幂,因为矩阵是循环矩阵,所以记录并处理第一行即可。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;const int maxn = 505;int N, M, D, K;struct Mat { ll arr[maxn];};Mat ceil, x;Mat mul_mat (const Mat& a, const Mat& b) { Mat ans; memset(ans.arr, 0, sizeof(ans.arr)); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) ans.arr[i] = (ans.arr[i] + a.arr[j] * b.arr[(i-j+N)%N]) % M; } return ans;}void pow_mat (int n) { Mat ans = x; while (n) { if (n&1) ans = mul_mat(ans, x); x = mul_mat(x, x); n >>= 1; } x = ans;}int main () { while (scanf("%d%d%d%d", &N, &M, &D, &K) == 4) { for (int i = 0; i < N; i++) scanf("%lld", &ceil.arr[i]); memset(x.arr, 0, sizeof(x.arr)); for (int i = -D; i <= D; i++) x.arr[(i+N)%N] = 1; pow_mat(K-1); /* for (int i = 0; i < N; i++) printf("%lld ", x.arr[i]); printf("\n"); */ for (int i = 0; i < N; i++) { if (i) printf(" "); ll ret = 0; for (int j = 0; j < N; j++) ret = (ret + ceil.arr[j] * x.arr[(j-i+N)%N]) % M; printf("%lld", ret); } printf("\n"); } return 0;}
0 0
- uva 1386 - Cellular Automaton(循环矩阵+矩阵快速幂)
- UVA 1386 cellular automaton [循环矩阵+矩阵快速幂]【数学】
- 【循环矩阵+矩阵快速幂】Cellular Automaton UVA
- UVA Live 3704 Cellular Automaton (循环矩阵+快速幂)
- UVA 1386 - Cellular Automaton(循环矩阵)
- UVA 1386 Cellular Automaton(循环矩阵)
- UVA - 1386 Cellular Automaton (矩阵快速幂)
- Poj 3150/UVA 1386/UVALive 3704 Cellular Automaton 循环矩阵
- uva 1386 - Cellular Automaton(循环矩阵乘)
- LA 3704 Cellular Automaton【循环矩阵,快速幂】
- LA 3704 Cellular Automaton / 矩阵快速幂
- POJ 3150 Cellular Automaton(矩阵快速幂)
- poj 3150Cellular Automaton(矩阵快速幂)
- poj3150 Cellular Automaton(矩阵快速幂)
- LA 3704 Cellular Automaton (矩阵快速幂)
- [FFT] [矩阵快速幂] [POJ3150] Cellular Automaton
- uva1386 - Cellular Automaton 循环矩阵
- Poj 3150 Cellular Automaton(矩阵快速幂, 循环矩阵快速幂)
- Swap Nodes in Pairs
- [big data] Azkaban
- POJ2001——Shortest Prefixes(Trie树模板)
- C/C++趣味程序百例
- [official] Azkaban
- uva 1386 - Cellular Automaton(循环矩阵+矩阵快速幂)
- public class PrimeNumber
- getDeclaredMethod 和 getMethod 的区别
- hdu 1011树形dp
- Android布局管理器的介绍与使用
- Linux设备驱动开发环境的搭建(转)
- filepath = path
- public class定义类
- 属性与内存管理(属性与内存管理都是相互关联的) 第一部分