【UVA】【第0章】457 - Linear Cellular Automata

来源:互联网 发布:有没有自动关机软件 编辑:程序博客网 时间:2024/05/17 01:36


 Linear Cellular Automata 

A biologist is experimenting with DNA modification ofbacterial colonies being grown in a linear array of culture dishes. Bychanging the DNA, he is able ``program" the bacteria to respond to thepopulation density of the neighboring dishes. Population is measuredon a four point scale (from 0 to 3). The DNA information isrepresented as an array DNA, indexed from 0 to 9, of population densityvalues and is interpreted as follows:

  • In any given culture dish, let K be 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 density ofDNA[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,0,0]). Others result in immediate populationexplosions (e.g., [3,3,3,3,3,3,3,3,3,3]). The biologist is interestedin how some of the less obvious intermediate DNA programs mightbehave.

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 allother dishes start with a population density of 0.

Input

The input begins with a single positive integer on a line by itselfindicating 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 betweentwo 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 outputsof two consecutive cases will be separated by a blank line.

For each input set it should print the densities of the 40 dishes for each of the next 50days. Each day's printout should occupy one line of 40 characters.Each dish is represented by a single character on that line. Zero populationdensities are to be printed as the character ` '. Population density 1will be printed as the character `.'. Population density 2 will beprinted as the character `x'. Population density 3 will be printed asthe character `W'.

Sample Input

10 1 2 0 1 3 3 2 3 0

Sample Output

bbbbbbbbbbbbbbbbbbb.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.xbx.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.bb.bb.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.........bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.xbbbbbbbx.bbbbbbbbbbbbbbbbbbbbbbbbbbbb.bbxbbbbbxbb.bbbbbbbbbbbbbbbbbbbbbbbbbb...xxxbbbxxx...bbbbbbbbbbbbbbbbbbbbbbbb.xb.WW.xbx.WW.bx.bbbbbbbbbbbbbbbbbbbbbb.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 ease of reading.The actual output file will use the ASCII-space character, not"b".

这道题的牛逼之处在于对题意的理解(UVA好像就这个最有挑战性,都习惯了)

就是说给你40个培养皿

第一天第20个培养皿上有细菌1个

叫你输出后49天后各个培养皿的情况

每个培养皿的情况依赖于前一天的自身情况与左右情况密度和

依赖关系映射在DNA【k】中

递推一遍就OK了

代码如下

#include <cstdlib>#include <cstring>#include <cstdio>#include <iomanip>#include <string>#include <algorithm>#include <iostream>using namespace std;int T;int DNA[10];int lV[51];int V[51];void init_file(){  freopen("White_GS_12.in", "r", stdin);  freopen("White_GS_12.out", "w", stdout);}void work(){for(int i = 0; i < 50; i++){  for(int j = 0; j < 40; j++)  {    lV[j] = V[j];  }  for(int j = 0; j < 40; j++)  {  if (V[j] == 0) printf(" ");  if (V[j] == 1) printf(".");  if (V[j] == 2) printf("x");  if (V[j] == 3) printf("W");  if (j == 0) V[j] = DNA[lV[j] + lV[j + 1]];  if (j == 39) V[j] = DNA[lV[j] + lV[j - 1]];  if (j > 0 && j < 39) V[j] = DNA[lV[j] + lV[j - 1] + lV[j + 1]];  }  printf("\n");}}void read_data(){scanf("%d", &T);while(T--){  memset(lV, 0, sizeof lV);  memset(V, 0, sizeof V);  lV[19] = 1;  V[19] = 1;  for(int i = 0; i < 10; i++)  {    scanf("%d", DNA + i);  }  work();  if (T != 0)printf("\n");}}int main(){init_file();read_data();return 0;}


原创粉丝点击