hdu 2276 Kiki & Little Kiki 2 矩阵快速幂
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 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
*/
// 对这个矩阵进行快速幂, 结果与初始状态相乘就好。
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
int n;
struct Matrix
{
int a[][];
Matrix() {
mem(a);
}
};
Matrix operator * (Matrix a, Matrix b) {
Matrix c;
for(int i = ; i<n; i++) {
for(int j = ; j<n; j++) {
for(int k = ; k<n; k++) {
c.a[i][j] += a.a[i][k]*b.a[k][j];
c.a[i][j] %= ;
}
}
}
return c;
}
Matrix operator ^ (Matrix a, ll b) {
Matrix tmp;
for(int i = ; i<n; i++)
tmp.a[i][i] = ;
while(b) {
if(b&)
tmp = tmp*a;
a = a*a;
b>>=;
}
return tmp;
}
int main()
{
int m;
string s;
while(cin>>m) {
cin>>s;
n = s.size();
Matrix tmp;
for(int i = ; i<n; i++) {
tmp.a[i][i] = ;
tmp.a[i][(i-+n)%n] = ;
}
Matrix b = tmp^m;
Matrix a;
for(int i = ; i<s.size(); i++) {
a.a[i][] = s[i]-'';
}
Matrix c = b*a;
for(int i = ; i<s.size(); i++) {
printf("%d", c.a[i][]);
}
cout<<endl;
}
return ;
}
hdu 2276 Kiki & Little Kiki 2 矩阵快速幂的更多相关文章
- HDU 2855 斐波那契+矩阵快速幂
http://acm.hdu.edu.cn/showproblem.php?pid=2855 化简这个公式,多写出几组就会发现规律 d[n]=F[2*n] 后面的任务就是矩阵快速幂拍一个斐波那契模板出 ...
- HDU 5950:Recursive sequence(矩阵快速幂)
http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:给出 a,b,n,递推出 f(n) = f(n-1) + f(n-2) * 2 + n ^ 4. f ...
- HDU 3292 【佩尔方程求解 && 矩阵快速幂】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=3292 No more tricks, Mr Nanguo Time Limit: 3000/1000 M ...
- HDU - 4965 Fast Matrix Calculation 【矩阵快速幂】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4965 题意 给出两个矩阵 一个A: n * k 一个B: k * n C = A * B M = (A ...
- hdu 4565 So Easy! (共轭构造+矩阵快速幂)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4565 题目大意: 给出a,b,n,m,求出的值, 解题思路: 因为题目中出现了开根号,和向上取整后求 ...
- HDU 2256 Problem of Precision 数论矩阵快速幂
题目要求求出(√2+√3)2n的整数部分再mod 1024. (√2+√3)2n=(5+2√6)n 如果直接计算,用double存值,当n很大的时候,精度损失会变大,无法得到想要的结果. 我们发现(5 ...
- hdu 1757 A Simple Math Problem_矩阵快速幂
题意:略 简单的矩阵快速幂就行了 #include <iostream> #include <cstdio> #include <cstring> using na ...
- HDU 5171 GTY's birthday gift 矩阵快速幂
GTY's birthday gift Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 1757 A Simple Math Problem (矩阵快速幂)
题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...
- HDU - 2604 Queuing(递推式+矩阵快速幂)
Queuing Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
随机推荐
- DOM常见属性及用法
1:innerHTML.outerHTML.innerText.outerText innerHTML: 设置或获取位于对象起始和结束标签内的HTML. outerHTML: 设置或获取对象及其内容的 ...
- Ubuntu 13.04下安装Vmware tools 9.2.3
更新13.04后 VmwareTools安装会出现三个问题 找不到generic kernel headers头文件 编译vmci出错 编译vmhgfs出错 第一个问题是系统的文件位置换了,而VMTO ...
- php将unicode编码转为utf-8方法
介绍 在前端开发中,为了让中文在不同的环境下都能很好的显示,一般是将中文转化为unicode格式,即\u4f60,比如:"你好啊"的 unicode编码为"\u4f60\ ...
- jquerymobile listview 局部刷新
function onSuccess(data, status) { data = $.trim(data); // alert(data); // return; if (data) { $('#l ...
- skynet的流程2
http://blog.csdn.net/xiarendeniao/article/details/38613161 http://www.jiandan.ren/2015/06/skynet-hel ...
- 论山寨手机与Android 【14】3G SmartPhone时代的MTK
分析了SmartPhone的里里外外以后,现在我们可以分析MTK的机遇和挑战了.MTK面临的外部环境在发生变化,变化有两条,一是移动网络从2G演变到3G,二是手机由FeaturePhone演化到Sma ...
- 项目与软件推荐之编辑器-QOwnNotes(刺激自己)
项目与软件推荐之编辑器-QOwnNotes 今天推荐一款软件 QOwnNotes,是一款普通文本笔记软件.以某个路径为目录,罗列出目录下所有的 md 文件或者 txt 文件. 有如下亮点: 启动速度快 ...
- Unicode其实是Latin1的扩展。只有一个低字节的Uncode字符其实就是Latin1字符——附各种字符编码表及转换表
一.概念 1,ASCII ASCII(American Standard Code for Information Interchange),中文名称为美国信息交换标准代码.是 ...
- poj 1007 纯水题 排序
#include<stdio.h> #include<string.h> #include<algorithm> #include<stdlib.h> ...
- 在JavaScript的数组中进行数组元素查找和替换(JS的indexOf等)
<html> <head> <title> Extend JavaScript Array Method </title> <script lan ...