Problem Description

There are n lights in a circle numbered from 1 to n. The left of light 1 is light n, and the left of light k (1< k<= n) is the light k-1.At time of 0, some of them turn on, and others turn off.

Change the state of light i (if it’s on, turn off it; if it is not on, turn on it) at t+1 second (t >= 0), if the left of light i is on !!! Given the initiation state, please find all lights’ state after M second. (2<= n <= 100, 1<= M<= 10^8)

Input

The input contains one or more data sets. The first line of each data set is an integer m indicate the time, the second line will be a string T, only contains ‘0’ and ‘1’ , and its length n will not exceed 100. It means all lights in the circle from 1 to n.

If the ith character of T is ‘1’, it means the light i is on, otherwise the light is off.

Output

For each data set, output all lights’ state at m seconds in one line. It only contains character ‘0’ and ‘1.

Sample Input

1 0101111 10 100000001

Sample Output

1111000 001000010

Source

HDU 8th Programming Contest Site(1)

Recommend

lcy | We have carefully selected several similar problems for you: 2256 2254 3117 2855 2971

每个灯的状态都由它左边那一个决定

构造出一个n*n的系数矩阵,每一行,每一列相应位置为1,

比方对于3个数的系数矩阵

1 1 0

0 1 1

1 0 1

那么初始为110的状态,1s以后即为101

也就是[1 1 0] 去乘上面那个矩阵得到的新矩阵

那么仅仅要矩阵高速幂加速即可了

/*************************************************************************
> File Name: hdu2276.cpp
> Author: ALex
> Mail: zchao1995@gmail.com
> Created Time: 2015年03月12日 星期四 21时28分55秒
************************************************************************/ #include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL; int n; class MARTIX
{
public:
int mat[110][110];
MARTIX();
MARTIX operator * (const MARTIX &b)const;
MARTIX& operator = (const MARTIX &b);
}; MARTIX :: MARTIX()
{
memset (mat, 0, sizeof(mat));
} MARTIX MARTIX :: operator * (const MARTIX &b)const
{
MARTIX ret;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
for (int k = 0; k < n; ++k)
{
ret.mat[i][j] += (this -> mat[i][k] * b.mat[k][j]);
ret.mat[i][j] %= 2;
}
}
}
return ret;
} MARTIX& MARTIX :: operator = (const MARTIX &b)
{
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
this -> mat[i][j] = b.mat[i][j];
}
}
return *this;
} MARTIX fastpow(MARTIX A, int m)
{
// void Debug(MARTIX A); MARTIX ret;
for (int i = 0; i < n; ++i)
{
ret.mat[i][i] = 1;
}
while (m)
{
if (m & 1)
{
ret = ret * A;
}
m >>= 1;
A = A * A;
}
return ret;
} void Debug(MARTIX A)
{
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
printf("%d ", A.mat[i][j]);
}
printf("\n");
}
} char str[110]; int main ()
{
int m;
while (~scanf("%d", &m))
{
scanf("%s", str);
MARTIX F;
n = strlen(str);
MARTIX A;
for (int i = 0; i < n - 1; ++i)
{
A.mat[i][i] = A.mat[i][i + 1] = 1;
}
A.mat[n - 1][0] = A.mat[n - 1][n - 1] = 1;
// Debug(A);
A = fastpow(A, m);
for (int i = 0; i < n; ++i)
{
F.mat[0][i] = str[i] - '0';
}
F = F * A;
for (int i = 0; i < n; ++i)
{
printf("%d", F.mat[0][i]);
}
printf("\n");
}
return 0;
}

hdu2276---Kiki &amp; Little Kiki 2(矩阵)的更多相关文章

  1. HDU2276 - Kiki &amp; Little Kiki 2(矩阵高速幂)

    pid=2276">题目链接 题意:有n盏灯.编号从1到n.他们绕成一圈,也就是说.1号灯的左边是n号灯.假设在第t秒的时候,某盏灯左边的灯是亮着的,那么就在第t+1秒的时候改变这盏灯 ...

  2. NYOJ 300 &amp;&amp; hdu 2276 Kiki &amp; Little Kiki 2 (矩阵高速功率)

    pid=300">Kiki & Little Kiki 2 时间限制:5000 ms  |  内存限制:65535 KB 难度:4 描写叙述 There are n light ...

  3. HDU - 2276 Kiki &amp; Little Kiki 2

    Description There are n lights in a circle numbered from 1 to n. The left of light 1 is light n, and ...

  4. HDU 2147 kiki's game kiki的游戏(博弈,找规律)

    题意: 给一个有n*m 个格子的棋盘,将一个硬币放在右上角一格,每次可以往左/下/左下移动一格,碰到不能移动的局面者输. 思路: 找P/N状态.先将(n,1)归为P状态,那么能一步到达此位置的有3个位 ...

  5. HDU2276 Kiki & Little Kiki 2 矩阵快速幂

    Kiki & Little Kiki 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  6. Linux基础学习-用户的创建修改删除

    用户添加修改删除 1 useradd添加用户 添加一个新用户hehe,指定uid为3000,家目录为/home/haha [root@qdlinux ~]# useradd -u 3000 -d /h ...

  7. HDU 2276 Kiki & Little Kiki 2(矩阵位运算)

    Kiki & Little Kiki 2 转载自:点这里 [题目链接]Kiki & Little Kiki 2 [题目类型]矩阵位运算 &题意: 一排灯,开关状态已知,每过一秒 ...

  8. HDU 2276 Kiki & Little Kiki 2 矩阵构造

    Kiki & Little Kiki 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  9. [HDU2276]Kiki & Little Kiki 2

    题目:Kiki & Little Kiki 2 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2276 分析: 1)如果前一盏灯亮着,则改变这一盏灯 ...

随机推荐

  1. nodejs express开发

    用NodeJS+Express开发WEB应用---第一篇 大漠穷秋2014-03-28 预热 为了对后面的内容理解更加透彻,推荐首先阅读下面这篇很好的文章: http://www.nodebeginn ...

  2. El表达式日期处理

    第1步:引入指令  <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt " %&g ...

  3. [BZOJ2321,LuoguP1861]星(之)器

    丧心病狂的神仙题 丧心病狂的神仙题 丧心病狂的神仙题 显然,不管你怎么移动,答案都是一定的 然后我们很快能联系到物理里面的能量守恒,于是自然地我们要给每个点搞一个势能出来 然后把势能的表达式写出来就可 ...

  4. xcode制作越狱后ipa安装文件

    正常情况下发布测试版给用户需要问到对方设备ID并添加到开发者证书里去感觉有点麻烦,如果是已越狱过的机器可以使用xcode制作ipa文件,并直接用itunes同步进去,这样方便多了. 将运行目标选为iO ...

  5. Android6.0以上版本获取本机蓝牙地址

    Android6.0以上版本使用BluetoothAdapter.getDefaultAdapter().getAddress()是获取不到正确的蓝牙地址的,返回的值都是02:00:00:00:00: ...

  6. 【Oracle】解决oracle sqlplus 中上下左右backspace不能用

    一. 解决输入 BACKSPACE 键变成 ^h 的问题 #su - oracle   $stty erase ^h. 要永久生效,可以加入到用户环境配置文件.bash_profile中(vi .ba ...

  7. 如何实现MySQL数据库使用情况的审计

    如何实现MySQL数据库使用情况的审计   最佳答案   mysql的审计功能 mysql服务器自身没有提供审计功能,但是我们可以使用init-connect + binlog的方法进行mysql的操 ...

  8. javaee字符缓冲输出流

    package Zjshuchu; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOExcepti ...

  9. apicloud iphoneX底部虚拟键盘遮挡

    1.首先,底部的高不能写死. 2. var footer = $api.byId('footer'); $api.fixTabBar(footer);这句应该写在 footerHeight = $ap ...

  10. 什么是Capability

    desired capability的功能是配置Appium会话.他们告诉Appium服务器您想要自动化的平台和应用程序. Desired Capabilities是一组设置的键值对的集合,其中键对应 ...