UVA - 1386 Cellular Automaton
来源:互联网 发布:思途旅游cms破解版 编辑:程序博客网 时间:2024/05/22 17:25
题目:点击打开链接
题意:一个细胞自动机包含n个格子,每个格子的值都会变成它距离不超过d的所有格子的值,求最后的结果
思路:这个是循环矩阵,可以用O(n^2)的时间过掉
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;const int maxn = 505;int n, m, d, k;ll ans[maxn], matrix[maxn];ll c[maxn+5];void mul(ll a[], ll b[]) {memset(c, 0, sizeof(c));for (int i = 0; i < n; i++) for (int j = 0; j < n; j++)c[i] += a[j] * b[(i-j+n) % n];for (int i = 0; i < n; i++) b[i] = c[i] % m;}int main() {while (scanf("%d%d%d%d", &n, &m, &d, &k) != EOF) {memset(ans, 0, sizeof(ans));memset(matrix, 0, sizeof(matrix));for (int i = 0; i < n; i++) cin>>ans[i];matrix[0] = 1;for (int i = 1; i <= d; i++) matrix[i] = matrix[n - i] = 1;while (k) {if (k & 1) mul(matrix, ans);mul(matrix, matrix);k >>= 1;}for (int i = 0; i < n - 1; i++) printf("%lld ", ans[i]);printf("%lld\n", ans[n-1]);}return 0;}
0 0
- UVA - 1386 Cellular Automaton
- UVa 1386 - Cellular Automaton
- UVA 1386 Cellular Automaton
- UVA 1386 - Cellular Automaton(循环矩阵)
- UVA 1386 Cellular Automaton(循环矩阵)
- Cellular Automaton UVA
- Poj 3150/UVA 1386/UVALive 3704 Cellular Automaton 循环矩阵
- uva 1386 - Cellular Automaton(循环矩阵乘)
- uva 1386 - Cellular Automaton(循环矩阵+矩阵快速幂)
- UVA 1386 cellular automaton [循环矩阵+矩阵快速幂]【数学】
- UVA - 1386 Cellular Automaton (矩阵快速幂)
- POJ 3150 / Uva 1386 Cellular Automaton 解题报告(循环矩阵)
- POJ 3150/ UVA 1386 Cellular Automaton(矩阵乘法&循环矩阵)
- UVA Live 3704 Cellular Automaton (循环矩阵+快速幂)
- 【循环矩阵+矩阵快速幂】Cellular Automaton UVA
- poj3150 Cellular Automaton
- poj 3150 Cellular Automaton
- POJ 3150 Cellular Automaton
- static关键字
- dynamic programming: coin change problem(换零钱) 变体一:
- C语言结构体总结
- 类型运算问题(面试细节)
- 动态数组的应用
- UVA - 1386 Cellular Automaton
- 你是猴子?
- 九度oj-1009-二叉搜索树
- java Math.round()用法
- Character Streams
- poj2159——我的代码一般都比较简洁,,,
- UVa11988 Broken Keyboard (a.k.a. Beiju Text)
- bzoj 1711: [Usaco2007 Open]Dingin吃饭
- 深入理解计算机系统(第二版) 读书笔记