zoj 1051
来源:互联网 发布:网络规划师华为 编辑:程序博客网 时间:2024/06/06 23:17
A New Growth Industry
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 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:
120 1 1 1 2 1 0 -1 -1 -1 -2 -2 -3 -3 -3 -33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Sample Output:
##!.................#!..................!............................................................................................................!..................!#!................!#X#!................!#!..................!..........................................................................................................................................................................
代码:
#include <stdio.h>#define M 20int main(){int casesum,days;int i,j,bl;int D[16];int input[M][M];int output[M][M]={0};scanf("%d",&casesum); bl=0;while(casesum--){scanf("%d",&days);for(i=0;i<16;i++){scanf("%d",&D[i]);}for (i=0;i<M;i++){for (j=0;j<M;j++){scanf("%d",&input[i][j]);}}while (days--){for(i=0;i<M;i++)for (j=0;j<M;j++){ output[i][j]=input[i][j];if(i-1>=0){output[i][j]+=input[i-1][j];}if (i+1<M){output[i][j]+=input[i+1][j];}if (j-1>=0){ output[i][j]+=input[i][j-1];}if (j+1<M){output[i][j]+=input[i][j+1];}}for (i=0;i<M;i++)for(j=0;j<M;j++){input[i][j]+=D[output[i][j]];if (input[i][j]>3){input[i][j]=3;}if (input[i][j]<0){input[i][j]=0;}}}for (i=0; i<M; i++){for (j=0; j<M; j++)switch (input[i][j]){ case 0: printf("."); break; case 1: printf("!"); break; case 2: printf("X"); break; case 3: printf("#");} printf("\n");}if (casesum){printf("\n");}}return 0;}
- zoj 1051
- zoj-1051
- ZOJ-1051
- zoj 1051
- ZOJ 1048 1049 1051
- ZOJ Problem Set - 1051
- ZOJ Problem Set - 1051
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- DrawText多行文本垂直居中
- 2011-8-28
- 挖挖Hive的代码(一)——UDF
- 用Java反射机制模拟hibernateJDBC操作
- Java还能在开源以后继续创造神话吗?
- zoj 1051
- iconv_substr截取字符而不是字节数,不用额外写自定义函数哦
- Maven仓库管理-Nexus(转帖后加强版)
- 设计模式入门之三
- vs2010 想用.net2.0,3,0或者其它低版本的框架的解决办法
- zoj 1067
- 带着你的思想去工作
- IO同步与异步
- 百万商业圈小型企业云ERP总体开发规划