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. [bzoj4444] 国旗计划 双指针+倍增

    Description A国正在开展一项伟大的计划--国旗计划.这项计划的内容是边防战士手举国旗环绕边境线奔袭一圈.这项计划需要多名边防战士以接力的形式共同完成,为此,国土安全局已经挑选了N名优秀的边 ...

  2. 《快学Scala》第五章 类

    关于case class和普通class的区别,可以参考: https://www.iteblog.com/archives/1508.html

  3. CentOS6.5下samba服务

    为减少错误已提前关掉了SELinux,防火墙. 安装rpm包: samba-3.6.9-164.el6.x86_64.rpm 启动检测:samba服务可以正常启动!(证明RPM安装正常) 配置文件位置 ...

  4. 爬虫5:beautifulsoup

      灵活方便的网页解析库,处理高效,支持多种解析器,利用它不用编写正则表达式即可方便的实现网页信息的提取     一. BeautifulSoup的几种解析库   解析器 使用方法 优势 劣势 Pyt ...

  5. mfix中输出DEM颗粒的固相速度到网格

    基于mfix-19.1.2版本 方法一:直接输出差值网格固相速度 注:这种方式只适用于garg 2012颗粒差值格式在DEM中,默认是无法输出固相速度的网格值的: 但是通过搜索des文件夹下V_s关键 ...

  6. 思科设备配置DHCP服务

    路由器,三层交换机都是可以做DHCP服务的,下面以Cisco 3750G-24TS-S为例配置DHCP服务,指令如下: ip dhcp pool DHCP-Server network 192.168 ...

  7. JavaIO流总结

    字节流 InputStream FileInputStream FilterInputStream BufferedInputStream DataInputStream PushbackInputS ...

  8. Hello Jexus(转并修改)

    一.关于 CentOS CentOS(Community ENTerprise Operating System)是Linux发行版之一,它是来自于Red Hat Enterprise Linux依照 ...

  9. mono 的System.Data.SqlClient小记录

    厦门-JuzzPig()  15:33:36System.Data.SqlClient 不科学的广州-PC286()  15:33:42webservice 返回的是 xml厦门-JuzzPig()  ...

  10. Visual Studio 跨平台開發實戰(4) - Xamarin Android 基本控制項介紹 (转帖)

    前言 不同於iOS, Xamarin 在Visual Studio中針對Android, 可以直接設計使用者介面. 在本篇教學文章中, 筆者會針對Android的專案目錄結構以及基本控制項進行介紹, ...