zoj1051--------A New Growth Industry 细菌~

把数组中的一个数,与其上下左右的四个数相加,得到的数值对应到DNA序列里面的对应数,把这个对应数加到原数组的对应位置,

然后超过三的为3,低于零的为0,处理后,即为一天的变化情况。

比如:

3 0 0             3 3 0             4 1 0            3 1 0
0 0 0  ——   3 0 0  ——   1 0 0 ——   1 0 0        这就是第一天的繁殖密度
0 0 0             0 0 0             0 0 0            0 0 0

 

代码如下:

#include <iostream>  
#include <string.h>   
using namespace std;  
  
const int DishSize = 20;       //培养皿是*20的大小   
char SignTable[]=".!X#";       //符号表     
int dish[DishSize][DishSize],res[DishSize][DishSize];     
int day,d[16];     
  
int main()     
{      
    int cases;          //测试样例数     
    int i,j,k;    
    while (cin>>cases)  
    {  
        while (cases--)  
        {     
            cin>>day;    //培养天数   
            //输入DNA序列信息   
            for (k=0; k<16; ++k)  
                cin>>d[k];  
           //输入培养皿数据   
            for (i=0; i<DishSize; ++i)     
                for (j=0; j<DishSize; ++j)     
                    cin>>dish[i][j];     
            while (day--)  
            {     
                for (i=0; i<DishSize; ++i)     
                    for (j=0; j<DishSize; ++j)  
                    {     
                        k = dish[i][j];    
                        //把其本身的值和上下左右的相加   
                        if (i-1>=0)   
                            k += dish[i-1][j];     
                        if (i+1<DishSize)   
                            k += dish[i+1][j];     
                        if (j-1>=0)  
                            k += dish[i][j-1];     
                        if (j+1<DishSize)   
                            k += dish[i][j+1];     
                        res[i][j] = dish[i][j]+d[k];     
                        //不能超过0~3的范围   
                        if (res[i][j]>3)  
                            res[i][j] = 3;     
                        if (res[i][j]<0)  
                            res[i][j] = 0;     
                    }     
                memcpy (dish,res,sizeof(dish));   //需要头文件#include <string.h>   
            }     
            for (i=0; i<DishSize; ++i)  
            {     
                for (j=0; j<DishSize; ++j)     
                    cout<<SignTable[dish[i][j]];     
                cout<<endl;     
            }     
              if (cases!=0)   
                cout<<endl;     
        }   
    }  
    return 0;     
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值