HDU 2276 Kiki & Little Kiki 2(矩阵快速幂)
来源:互联网 发布:牙签弩淘宝多少钱 编辑:程序博客网 时间:2024/04/30 06:16
Kiki & Little Kiki 2
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2265 Accepted Submission(s): 1146
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)
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.
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
1010111110100000001
Sample Output
1111000001000010
Source
HDU 8th Programming Contest Site(1)
Recommend
lcy | We have carefully selected several similar problems for you: 1757 1588 2604 2256 2294
#pragma comment(linker, "/STACK:1024000000,1024000000")#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<stack>#include<vector>#include<set>#include<map>#define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)#define bug printf("hihi\n")#define eps 1e-8typedef __int64 ll;using namespace std;#define INF 0x3f3f3f3f#define N 101int n;struct mat{ mat(){memset(a,0,sizeof(a));} int a[N][N]; mat operator *(mat b) { mat c; for(int i=0;i<n;i++) for(int j=0;j<n;j++) for(int k=0;k<n;k++) c.a[i][j]=(c.a[i][j]+a[i][k]*b.a[k][j])%2; return c; }};mat fdd(mat s,int m){ mat ss; for(int i=0;i<n;i++) ss.a[i][i]=1; while(m) { if(m&1) ss=ss*s; s=s*s; m>>=1; } return ss;}int main(){ int i,j; char c[1000]; int m; while(~scanf("%d",&m)) { scanf("%s",c); mat s; n=strlen(c); for(i=0;i<n;i++) s.a[i][0]=c[i]-'0'; mat ss; ss.a[0][0]=ss.a[0][n-1]=1; for(i=1;i<n;i++) ss.a[i][i]=ss.a[i][i-1]=1; ss=fdd(ss,m); s=ss*s; for(i=0;i<n;i++) printf("%d",s.a[i][0]); printf("\n"); } return 0;}
0 0
- HDU 2276 Kiki & Little Kiki 2(矩阵快速幂)
- HDU 2276 Kiki & Little Kiki 2 (矩阵快速幂)
- hdu 2276 Kiki & Little Kiki 2(矩阵快速幂)
- HDU 2276 Kiki & Little Kiki 2 矩阵快速幂
- HDU 2276 Kiki & Little Kiki 2(矩阵快速幂)
- hdu 2276 Kiki & Little Kiki 2 (矩阵快速幂)
- HDU - 2276 Kiki & Little Kiki 2 矩阵快速幂
- hdu 2276 Kiki & Little Kiki 2矩阵快速幂
- hdu 2276 Kiki & Little Kiki 2 矩阵快速幂
- HDU 2276 Kiki & Little Kiki 2 (位运算+矩阵快速幂)
- NYOJ 300 && hdu 2276 Kiki & Little Kiki 2 (矩阵快速幂)
- HDU 2276-Kiki & Little Kiki 2(矩阵快速幂+位运算)
- hdoj 2276 Kiki & Little Kiki 2【矩阵快速幂】
- Kiki & Little Kiki 2(矩阵快速幂(推理))
- nyoj 300 (矩阵快速幂)Kiki & Little Kiki 2
- hdu 2276 Kiki & Little Kiki 2(矩阵乘法)
- hdu 2276 Kiki & Little Kiki 2(矩阵递推)
- Hdu 2276 && Nyoj 300 Kiki & Little Kiki 2[矩阵快速幂]
- CentOS 上apache+Subversion搭建及常见问题处理
- JavaScript学习笔记
- sass
- HDU - 4277(暴力加+hash)
- BZOJ2223 PATULJCI COCI2009_CONTSET3
- HDU 2276 Kiki & Little Kiki 2(矩阵快速幂)
- 检查究竟哪个程序消耗本地mac的网络流量
- Unity3d动画脚本 Animation Scripting(深入了解游戏引擎中的动画处理原理)
- 关于onDraw()方法不被执行的解决方法(setWillNotDraw(false))
- 0xC0000005: 读取位置 0x0000000000000000 时发生访问冲突 异常处理问题解决办法
- 单词接龙
- ListView
- SDL声音播放设备
- JavaScript中使用prototype来扩展对象,举例