编程介的小学生 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
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形