ZJU ACM 1051 A New Growth Industry

來源:互聯網
上載者:User

 

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;  
}

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.