您的位置:首页 > 其它

poj 1120题目难懂啊

2016-05-23 19:55 211 查看
A New Growth Industry

Time Limit: 1000MSMemory Limit: 10000K
Total Submissions: 2597Accepted: 1229
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?, 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
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#!........
........!#!.........
.........!..........
....................
....................
....................
....................
....................
....................
....................
....................


题意:

题目意思就是培养细菌,每天一代。

先给定D这个数组,长度固定为16

给定一个20 * 20的矩阵,表示培养基

现在在这个培养基上面,每一个点的细菌增长安照D这个数组进行,每一个点的数值加上这个点的上下 左右的点的数值为 K,那么这个点的第二天的数值是 前一天的数值加上D[ K ];

注意:上面题目中红色字体的理解,表示在前一天的基础上进行的

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

int days;
int d[20],a[25][25],temp[25][25];
int dx[5]={0,0,1,-1};
int dy[5]={1,-1,0,0};

int deal(int x,int y)
{
int tempx,tempy;
int ans=a[x][y];
for(int i=0;i<4;i++){
tempx=x+dx[i];
tempy=y+dy[i];
ans+=a[tempx][tempy];
}
return ans;
}

int main()
{
memset(a,0,sizeof(a));
scanf("%d",&days);
for(int i=0;i<=15;i++)
scanf("%d",&d[i]);
for(int i=1;i<=20;i++)
for(int j=1;j<=20;j++)
scanf("%d",&a[i][j]);

while(days--)
{
for(int i=1;i<=20;i++){
for(int j=1;j<=20;j++){
temp[i][j]=a[i][j]+d[deal(i,j)];

if(temp[i][j]<0)
temp[i][j]=0;
else if(temp[i][j]>3)
temp[i][j]=3;
}
}

for(int i=1;i<=20;i++)
for(int j=1;j<=20;j++)
a[i][j]=temp[i][j];
}

for(int i=1;i<=20;i++){
for(int j=1;j<=20;j++){
if(a[i][j]==0){
printf(".");
continue;
}
else if(a[i][j]==1){
printf("!");
continue;
}
else if(a[i][j]==2){
printf("X");
continue;
}
else{
printf("#");
continue;
}
}
puts("");
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: