HDU 1057 模拟

来源:互联网 发布:MAC maven安装配置 编辑:程序博客网 时间:2024/06/06 07:03

HDU 1057

A New Growth Industry

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1733    Accepted Submission(s): 731


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

Source
Mid-Atlantic USA 2001
 

Recommend
PrincetonBoy

很好的模拟水题,也是很好的英语阅读。

题意:

第一行数据组数

第二行模拟次数

第三行是变换规则表。

随后给你一个20*20的初始状态表。

#include <iostream>#include <cstring>#include <cstdio>using namespace std;int main(){    int a[25][25],b[25][25],day,t,c[20];    while(cin>>t)    {        while(t--)        {            cin>>day;            for(int i=0;i<16;i++)                scanf("%d",&c[i]);            memset(a,0,sizeof(a));            memset(b,0,sizeof(b));            for(int i=1;i<=20;i++)            {                for(int j=1;j<=20;j++)                    scanf("%d",&a[i][j]);            }            while(day--)            {                for(int i=1;i<=20;i++)                    for(int j=1;j<=20;j++)                    {                        b[i][j]=a[i][j]+c[a[i][j]+a[i-1][j]+a[i+1][j]+a[i][j-1]+a[i][j+1]];变化规则:对于每一个位置计算其上下左右和其本身的和,跟据这个和sum,在变化规则表中找相应的变化值c[sum]。                        if(b[i][j]>3)一个位置上的数最大为3                            b[i][j]=3;                        else if(b[i][j]<0)最小为0                            b[i][j]=0;                    }                for(int i=1;i<=20;i++)                    for(int j=1;j<=20;j++)                    a[i][j]=b[i][j];            }            for(int i=1;i<=20;i++)            {                for(int j=1;j<=20;j++)                if(a[i][j]==0) printf(".");                else if(a[i][j]==1) printf("!");                else if(a[i][j]==2) printf("X");                else printf("#");                printf("\n");            }            if(t)            printf("\n");        }    }}


0 0
原创粉丝点击