杭电1057

Problem Description


A biologist experimenting with DNA modification of bacteria has found a way to make bacterial colonies sensitive to the 
surrounding population density. By changing the DNA, he is able to “program” the bacteria to respond to the varying densities in their immediate neighborhood. 

The culture dish is a square, divided into 400 smaller squares (20x20). Population in each small square is measured on a four point scale (from 0 to 3). The DNA information is represented as an array D, indexed from 0 to 15, of integer values and is interpreted as follows: 

In any given culture dish square, let K be the sum of that square's density and the densities of the four squares immediately to the left, right, above and below that square (squares outside the dish are considered to have density 0). Then, by the next day, that dish square's density will change by D[K] (which may be a positive, negative, or zero value). The total density cannot, however, exceed 3 nor drop below 0. 

Now, clearly, some DNA programs cause all the bacteria to die off (e.g., [-3, -3, …, -3]). Others result in immediate population explosions (e.g., [3,3,3, …, 3]), and others are just plain boring (e.g., [0, 0, … 0]). The biologist is interested in how some of the less obvious DNA programs might behave. 

Write a program to simulate the culture growth, reading in the number of days to be simulated, the DNA rules, and the initial population densities of the dish.
 

Input
Input to this program consists of three parts: 

1. The first line will contain a single integer denoting the number of days to be simulated. 

2. The second line will contain the DNA rule D as 16 integer values, ordered from D[0] to D[15], separated from one another by one or more blanks. Each integer will be in the range -3…3, inclusive. 

3. The remaining twenty lines of input will describe the initial population density in the culture dish. Each line describes one row of squares in the culture dish, and will contain 20 integers in the range 0…3, separated from one another by 1 or more blanks. 
 

Output
The program will produce exactly 20 lines of output, describing the population densities in the culture dish at the end of the simulation. Each line represents a row of squares in the culture dish, and will consist of 20 characters, plus the usual end-of-line terminator. 

Each character will represent the population density at a single dish square, as follows: 



No other characters may appear in the output. 
 

Sample Input
  
  
1 2 0 1 1 1 2 1 0 -1 -1 -1 -2 -2 -3 -3 -3 -3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 

Sample Output
  
  
##!................. #!.................. !................... .................... .................... .................... .................... .........!.......... ........!#!......... .......!#X#!........ ........!#!......... .........!.......... .................... .................... .................... .................... .................... .................... .................... ....................
开始没看懂,很难。后面搜了一下,先看要繁殖的天数,然后根据对应位置已有的细胞数与周围的数目之和,在与输入的那组数据比较加上原来的已有的细胞数,依次类推,得到以后的数目。(大于3为3,小于0为0)
#include<iostream>
#include <string>
using namespace std;
int main()
{
	int a;
	int ls[22][22];
	int l[22][22],s[16];
	char L[4]={'.','!','X','#'};
	scanf("%d",&a);
	while(a--)
	{
		int D;
		memset(ls,0,sizeof(ls));
		memset(l,0,sizeof(l));
		scanf("%d",&D);
		int i,j;
		for(i=0;i<16;i++)
			scanf("%d",&s[i]);
		for(i=1;i<=20;i++)	
			for(j=1;j<=20;j++)		
				scanf("%d",&ls[i][j]);
		while(D--)
		{


			for(i=1;i<=20;i++)
			{
				for(j=1;j<=20;j++)
				{
					int HK=0;
					HK=ls[i][j]+ls[i][j+1]+ls[i][j-1]+ls[i+1][j]+ls[i-1][j];
					l[i][j]=ls[i][j]+s[HK];
					if(l[i][j]>3)
						l[i][j]=3;
					if(l[i][j]<0)
						l[i][j]=0;
				}
			}
			memcpy(ls,l,sizeof(l));
		}
		for(i=1;i<=20;i++)
		{
			for(j=1;j<=20;j++)
			{
				printf("%c",L[ls[i][j]]);
			}
			printf("\n");
		}
		if(a)
			printf("\n");
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值