现在的位置: 首页 > 综合 > 正文

ZJU ACM 1051 A New Growth Industry

2013年09月07日 ⁄ 综合 ⁄ 共 5010字 ⁄ 字号 评论关闭

 

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).(K等于 一个小方块本身的密度+加上它上下左右四个方块的密度) Then, by the next day,that dish square's density will change by D[K] (which may be a positive, negative, or zero value).(第二天,加上DNA信息数列D[K],表示为当前方块更新后的密度) The total density cannot, however, exceed 3 nor drop below 0. (大于3则等于3,小于0则等于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 Format:

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 Format:

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.

This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.

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#!........
........!#!.........
.........!..........
....................
....................
....................
....................
....................
....................
....................
....................

 

 

 

//简单的数组处理题,就是题目不大好懂,其实主要信息就是第二段我翻译的内容

//下面贴上解题代码,转自:http://blog.csdn.net/phinecos/archive/2008/10/23/4612058.aspx

 

 

#include <iostream>
using namespace std;

const int  MAXNUM = 20;//培养皿是*20的大小
char SignTable[]=".!X#";//符号表 
int dish[MAXNUM][MAXNUM],res[MAXNUM][MAXNUM];  
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<MAXNUM; ++i)  
                for (j=0; j<MAXNUM; ++j)  
                    cin>>dish[i][j];  
            while (day--)
            {  
                for (i=0; i<MAXNUM; ++i)  
                    for (j=0; j<MAXNUM; ++j)
                    {  
                        k = dish[i][j]; 
                        //和上下左右的结合起来
                        if (i-1>=0)
                            k += dish[i-1][j];  
                        if (i+1<MAXNUM)
                            k += dish[i+1][j];  
                        if (j-1>=0)
                            k += dish[i][j-1];  
                        if (j+1<MAXNUM)
                            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));  
            }  
            for (i=0; i<MAXNUM; ++i)
            {  
                for (j=0; j<MAXNUM; ++j)  
                    cout<<SignTable[dish[i][j]];  
                cout<<endl;  
            }  
            //样例之间有一个空行
            if (cases!=0)
                cout<<endl;  
        }
    }
    return 0;  
}

 

 

 

抱歉!评论已关闭.