Kiki & Little Kiki 2

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1659    Accepted Submission(s): 837

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
 
Recommend
lcy
 
 /*
题意:一个灯环,输出进行N此变化的结果,变化的规则是:如果左边是1,那么自己变成相反的
1变成0 0变成1 。第一个要以最后一个为参考。 矩阵的变化, | 1 0 0 0 0 1| a1 | (a1+a6)%2 |
| 1 1 0 0 0 0| a2 | (a1+a2)%2 |
| 0 1 1 0 0 0| a3 === | (a2+a3)%2 |
| 0 0 1 1 0 0| a4 | (a3+a4)%2 |
| 0 0 0 1 1 0| a5 | (a4+a5)%2 |
| 0 0 0 0 1 1| a6 | (a5+a6)%2 | 利用矩阵相乘就可以快速到求取出来.
优化1.由于左边是稀疏矩阵,那么在矩阵相乘到时候,可以优化。代码中有!!~
优化2.用位操作。怎么用位操作实现?
优化3.在快速幂的时候,顺序的变化。因为稀疏矩阵的存在,所以改变一下顺序
就会有提高。代码中有...
*/ #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std; char a[];
struct node
{
int mat[][];
}M_tom,M_hxl; void make_first(node *cur,int len)
{
int i,j;
for(i=;i<=len;i++)
for(j=;j<=len;j++)
if(i==j) cur->mat[i][j]=;
else cur->mat[i][j]=;
} void cheng2(node cur,char a[],int len)
{
node ww;
int i,j,k;
memset(ww.mat,,sizeof(ww.mat));
for(i=;i<=len;i++)
for(k=;k<=len;k++)
if(cur.mat[i][k])
{
for(j=;j<=;j++)
{
ww.mat[i][j]=(ww.mat[i][j]^(cur.mat[i][k]&(a[k]-'')))&;
}
}
for(i=;i<=len;i++)
printf("%d",ww.mat[i][]);
printf("\n");
} struct node cheng(node cur,node now,int len)
{
node ww;
int i,j,k;
memset(ww.mat,,sizeof(ww.mat));
for(i=;i<=len;i++)
for(k=;k<=len;k++)
if(cur.mat[i][k])//对稀疏矩阵的优化
{
for(j=;j<=len;j++)
{
if(now.mat[k][j])//同理
{
ww.mat[i][j]=(ww.mat[i][j]^(cur.mat[i][k]&now.mat[k][j]))&;
}
}
}
return ww;
} void make_init(int len)
{ for(int i=;i<=len;i++)
M_hxl.mat[][i]=; M_hxl.mat[][]=;
M_hxl.mat[][len]=;
for(int i=;i<=len;i++)
for(int j=;j<=len;j++)
if(i==j || i-==j)
M_hxl.mat[i][j]=;
else M_hxl.mat[i][j]=;
} void power_sum2(int n,int len,char a[])
{
make_first(&M_tom,len);
while(n)
{
if(n&)
{
M_tom=cheng(M_hxl,M_tom,len);//这也是优化。顺序改变结果就不同了
}
n=n>>;
M_hxl=cheng(M_hxl,M_hxl,len);
}
// cs(len);
cheng2(M_tom,a,len);
} int main()
{
int n,len;
while(scanf("%d",&n)>)
{
scanf("%s",a+);
len=strlen(a+);
make_init(len);
power_sum2(n,len,a);
}
return ;
}

HDU 2276 Kiki & Little Kiki 2 矩阵构造的更多相关文章

  1. 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 ...

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

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

  3. hdu 2276 Kiki & Little Kiki 2

    点击打开hdu 2276 思路: 矩阵快速幂 分析: 1 题目给定一个01字符串然后进行m次的变换,变换的规则是:如果当前位置i的左边是1(题目说了是个圆,下标为0的左边是n-1),那么i就要改变状态 ...

  4. HDU 2276 矩阵快速幂

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

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

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

  6. [HDU2276]Kiki & Little Kiki 2

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

  7. HDU 2276 Kiki & Little Kiki 2( 矩阵快速幂 + 循环同构矩阵 )

    蒟蒻的我还需深入学习 链接:传送门 题意:给出一个长度为 n,n 不超过100的 01 串 s ,每当一个数字左侧为 1 时( 0的左侧是 n-1 ),这个数字就会发生改变,整个串改变一次需要 1s ...

  8. hdu 2276 Kiki & Little Kiki 2 矩阵快速幂

    题目链接 n个灯围成一圈, 1左边是n. 有两种状态, 1是亮, 0是不亮. 如果一个灯, 它左边的灯是亮的, 那么下一时刻这个灯就要改变状态, 1变为0, 0变为1. 给出初始状态和时间t, 问t时 ...

  9. 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 ...

随机推荐

  1. mxonline实战2, 后台管理神器xadmin

          对应github地址:xadmin的使用   第三天:xadmin的安装以及各应用模型的后台管理注册     一. 安装xamdin     1. 源码包下载地址 https://gith ...

  2. 1.HTML练习(二)

    一.表格练习: 1.<table>标签:声明一个表格,它的常用属性如下: border属性             定义表格的边框,设置值是数值 cellpadding属性     定义单 ...

  3. JSP里面九个内置对象

    JSP内置对象(9个常用的内置对象) 1.request对象 客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求, 然后做出响应.它是HttpServletRequest类的实例 ...

  4. mac编辑器vim美化

    mac编辑器vim美化 contents 环境 效果呈现 安装 quick start 环境 mac10.13.6,vim7(该版本mac自带的vim是7),git mac下vim的配置文件有两处 一 ...

  5. iOS学习笔记(4)——显示单组件选取器

    1. 创建工程 创建新工程,create a new Xcode project 创建single view application 创建名为PickerViewTest的工程 2. 创建xib文件 ...

  6. 解决Python向MySQL数据库插入中文数据时出现乱码

    解决Python向MySQL数据库插入中文数据时出现乱码 先在MySQL命令行中输入如下语句查看结果: 只要character_set_client character_set_database ch ...

  7. c语言求方阵的行列式、伴随矩阵算法

    #include<stdio.h> #include<math.h> #define N 100 //N比输入的阶数大即可 int main() {   int n,a[N][ ...

  8. POJ 2215

    //package j; import java.util.*; public class Main { public static void main(String args[]){ int r; ...

  9. day4. python学习之字典

    字典和列表是最常用的数据类型,字典是一种key-value的数据类型,用{ }表示 1.字典的特性:无序的,没有下标 2.字典的使用:增删改查 info = { '20181101':"zh ...

  10. ADC新库

    1.单次采集模式 1.在STM32CUBMX中设置为单次采集模式 2.在C文件中用HAL_ADC_START()函数启动ADC 3.用HAL_ADC_PollForConversion()延时等待采集 ...