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

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名