Uva_457 linear Cellular Automation

Source: Internet
Author: User
Linear Cellular Automata

A biologist is experimenting with DNA modification of bacterial colonies being grown in a linear array of culture dishes. by changing the DNA, he is able ''program "the bacteria to respond to the population density of the neighboring dishes. population is measured on a four point scale (from 0 to 3 ). the DNA information is represented as an arrayDNA, Indexed from 0 to 9, of population density values and is interpreted as follows:

  • In any given culture dish, letKBe the sum of that culture dish's density and the densities of the dish immediately to the left and the Dish immediately to the right. then, by the next day, that dish will have a population densityDNA [k].
  • The dish at the far left of the line is considered to have a left neighbor with population density 0.
  • The dish at the far right of the line is considered to have a right neighbor with population density 0.

Now, clearly, some DNA programs cause all the bacteria to die off (e.g ., [0, 0, 0, 0, 0, 0, 0, 0]). others result in immediate population explosions (e.g ., [3, 3, 3, 3, 3, 3, 3, 3]). the biologist is interested in how some of the less obvious intermediate DNA programs might behave.

Write a program to simulate the Culture Growth in a line of 40 dishes, assuming that dish 20 starts with a population density of 1 and all other dishes start with a population density of 0.

Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. this line is followed by a blank line, and there is also a blank line between two consecutive inputs.

For each input set your program will read in the DNA Program (10 integer values) on one line.

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

For each input set it shoshould print the densities of the 40 dishes for each of the next 50 days. each day's printout shocould occupy one line of 40 characters. each dish is represented by a single character on that line. zero population densities are to be printed as the character ''. population density 1 will be printed as the character'.'. Population density 2 will be printed as the character'X'. Population density 3 will be printed as the character'W'.

Sample Input
1

0 1 2 0 1 3 3 2 3 0
Sample output
bbbbbbbbbbbbbbbbbbb.bbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbb...bbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbb.xbx.bbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbb.bb.bb.bbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbb.........bbbbbbbbbbbbbbbb
bbbbbbbbbbbbbb.xbbbbbbbx.bbbbbbbbbbbbbbb
bbbbbbbbbbbbb.bbxbbbbbxbb.bbbbbbbbbbbbbb
bbbbbbbbbbbb...xxxbbbxxx...bbbbbbbbbbbbb
bbbbbbbbbbb.xb.WW.xbx.WW.bx.bbbbbbbbbbbb
bbbbbbbbbb.bbb.xxWb.bWxx.bbb.bbbbbbbbbbb
 

Note:Whe show only the first ten lines of output (the total number of lines must be 50) and the spaces have been replaced with the character"B"For reading of reading. The actual output file will use the ascii-space character, not"B".

After reading it for two hours, I didn't understand what it meant. It seems that English is too bad !!!

 

View code

#include<stdio.h>
#include<string.h>

int main()
{
int n, i, j, k;
scanf("%d", &n);
for(i =0;i < n;i++)
{
int pre[50]={0}, cur[50] = {0}, temp, dic[10];
cur[20] =1;
for(j =0;j <10;j ++)
{
scanf("%d", &dic[j]);

}
for(j =0;j <50;j ++)
{
for(k =1;k <=40;k ++)
{
if(cur[k]==0) printf("");
elseif(cur[k]==1) printf(".");
elseif(cur[k]==2) printf("x");
else printf("W");
}
printf("\n");
memcpy(pre, cur, sizeof(pre));
for(k =1;k <=40;k ++)
{
temp = pre[k] + pre[k-1] + pre[k+1];
cur[k] = dic[temp];
}
}
if(i!=n-1) printf("\n");
}
return0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.