acm-Kiki & Little Kiki 2

Kiki & Little Kiki 2

时间限制: 5000  ms  内存限制: 65535  KB
难度: 4
描述
There are n lights in a circle numbered from 1 to n. The left oflight 1 is light n, and the left of light k (1< k<= n) is thelight k-1.At time of 0, some of them turn on, and others turnoff. 
Change the state of light i (if it's on, turn off it; if it is noton, turn on it) at t+1 second (t >= 0), if the left of light iis on !!! Given the initiation state, please find all lights’ stateafter M second. (2<= n <= 100, 1<= M<=10^8)
输入
The input contains no more than 1000 data sets. The first line ofeach data set is an integer m indicate the time, the second linewill be a string T, only contains '0' and '1' , and its length nwill not exceed 100. It means all lights in the circle from 1 ton.
If the ith character of T is '1', it means the light i is on,otherwise the light is off.
输出
For each data set, output all lights' state at m seconds in oneline. It only contains character '0' and '1.
样例输入
1
0101111
10
100000001
样例输出
1111000
001000010
来源
hdu
 
#include
#include
#include
#include
using namespace std;
const int MAXN = 105;
int n , len;
char str[MAXN];
struct Matrix{
      intmat[MAXN][MAXN];
      Matrixoperator*(const Matrix& m)const{
              Matrix tmp;
              for(int i = 0 ; i < len ; i++){
                      for(int j = 0 ; j < len ; j++){
                              tmp.mat[i][j] = 0;   
                              for(int k = 0 ; k < len ; k++)
                                      tmp.mat[i][j] ^= (mat[i][k]&m.mat[k][j]);
                      }
              }
              return tmp;
      }
};
void solve(){
      len =strlen(str);
      Matrix m ,ans;
      memset(m.mat, 0 , sizeof(m.mat));
      for(int i =1 ; i < len ; i++)
              m.mat[i][i] = m.mat[i][i-1] = 1;
      m.mat[0][0]= m.mat[0][len-1] = 1;
      memset(ans.mat , 0 , sizeof(ans.mat));
      for(int i =0 ; i < len ; i++)
              ans.mat[i][i] = 1;
      while(n){
              if(n&1)
                      ans = ans*m;
              n >>= 1;
              m = m*m;
      }
      for(int i =0 ; i < len ; i++){
              int x = 0;
              for(int k = 0 ; k < len ; k++)
                      x ^= ans.mat[i][k]&(str[k]-'0');
              printf("%d" , x);
      }
      puts("");
}
int main(){
      while(scanf("%d%s" , &n , str) != EOF)
              solve();
      return0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值