博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVALive 4034
阅读量:4463 次
发布时间:2019-06-08

本文共 2737 字,大约阅读时间需要 9 分钟。

 Game of Life
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

LIFE is a evolutionary game played on a 2D game board. Initially, the game board is filled with white and black stones. For each iteration of the game, each stone is checked and perhaps changed to the other color according to the rules given below:

 

  1. For each stone i , if there are more black stones than white stones in the 3×3 neightborhood centered at stone i , then turn stone i into a black stone, otherwise, turn it to a white stone. The checking is based on the previous iterated game board configuration, and NOT the current iteration of intermediate game board. In other words, the check of all stones are done simultaneously. Thus, changing the stone color will not affect any other stone in the same iteration.
  2. The boundary of the game board will remain unchanged throughout all iterations. In other words, there is no need to check the stones located on the boundary of the game board.

Please write a program that when given an initial game board configuration and the number of iterations of LIFE, compute and output the number of black and white stones on the resulting game board.

 

Technical Specification

 

  1. The game board size is m×m where 3$ \le$m$ \le$512 .
  2. The number of iterations is t , where 1$ \le$t$ \le$100 .

Input

The first line of the input contains an integer n indicating the number of test cases to follow. For each test case, the first line contains two integers, m and t , specifying the game board dimension and number of LIFE iterations. The next m lines outline the configuration of the initial m×m game board. Each line contains m consecutive characters, where each character is either ``b" or ``w" denoting black stone or white stone, respectively.

Output

For each test case, output on a single line the number of black stones and white stones of the resulting game board.

 

Note: The final game board configuration for the below two cases are:

 

wbwb bbbw wbbb wbwb wbbbb wwbww wwwww wwwww wwwww

Sample Input

 

2 4 1 wbwb bbbw wwbb wbwb 5 1 wbbbb wbwbw wwwww wwwww wwwww

Sample Output

 

10 6 5 20
//模拟题 #include 
#include
#include
#include
#include
#include
using namespace std;char map[523][523];int rc[10000][2];int C;bool del(int &i,int &j){ int x,y; int ct=0; for(x=i-1;x<=i+1;x++) for(y=j-1;y<=j+1;y++) if(map[x][y]=='b') ct++; if(map[i][j]=='b') { if(ct<5) { return 1; } } else { if(ct>4) return 1; } return 0;}int main(){ int T; int m,t; int i,j,k; scanf("%d",&T); while(T--) { scanf("%d%d",&m,&t); for(i=1;i<=m;i++) scanf("%s",map[i]+1); while(t--) { C=0; for(i=2;i

转载于:https://www.cnblogs.com/372465774y/archive/2012/07/26/2609380.html

你可能感兴趣的文章
ServletContext对象的使用
查看>>
Python-aiohttp百万并发
查看>>
leetcode--Permutation Sequence
查看>>
[转载] 腾讯开源的rapidjson
查看>>
关于Oracle数据库字符集
查看>>
Cookie Session 与Token
查看>>
[POJ1655]Balancing Act
查看>>
存储过程
查看>>
搭建mongodb注意事项
查看>>
按ECS退出全屏模式
查看>>
5.4下午数学
查看>>
【软工】第 一 次作业 (阅读作业)
查看>>
素材网
查看>>
django
查看>>
mysql双1设置
查看>>
视觉差滚动--展示图片
查看>>
网页自动添加qq好友
查看>>
Myeclipse 如何解决反应慢的问题
查看>>
HDU POJ 1015 Jury Compromise(陪审团的人选,DP)
查看>>
Bubble Sort冒泡排序
查看>>