编程介的小学生 2017-09-03 01:44 采纳率: 20.5%
浏览 723
已采纳

Life on a Ring

The Game of Life is not your typical computer game. It is a 'cellular automaton', and was invented by Cambridge mathematician John Conway.
This game became widely known when it was mentioned in an article published by Scientific American in 1970. It consists of a collection of cells which, based on a few mathematical rules, can live, die or multiply. Depending on the initial conditions, the cells form various patterns throughout the course of the game.

Now, let's define a similar but much easier version of The Game of Life. All the cells lie on a ring, each cell has four neighboring positions: those at distance one or two from it on each side. The rules are similar to those of two-dimensional Life except (1) a dead cell with either two or three living neighbors will become alive in the next generation, and (2) a living cell dies if it has zero, one, or three living neighbors. (Hence a dead cell with zero, one, or four living neighbors stays dead; a living cell with two or four living neighbors stays alive.)

Given an initial condition of the cells, you're to find the layout of the selected generation.

Input

Each case begin with a line with two positive integers N (5 <= N <= 20) and T, the size of the ring and the generation you're to find. The second line contains N integers (0 and 1), indicating a dead cell and a living cell.

Input cases are separated with a blank line. Proceed to the end of file.

Output

For each case, print the layout in a line, same as input. There is one space between numbers.

Sample Input

5 1
0 1 0 1 0

7 2
0 1 0 1 1 1 0

Sample Output

1 0 1 0 1
0 1 1 1 0 0 0

  • 写回答

1条回答 默认 最新

  • devmiao 2017-09-03 14:53
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况