UVa 457 Linear Cellular Automata (water ver.)
来源:互联网 发布:nginx 配置 centos7.2 编辑:程序博客网 时间:2024/05/17 07:42
457 - Linear Cellular Automata
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=398
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 array DNA, indexed from 0 to 9, of population density values 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 of DNA[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 population explosions (e.g., [3,3,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 should print the densities of the 40 dishes for each of the next 50 days. Each day's printout should 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
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".
样例输出没写完,反正输出50行就是。
完整代码:
/*0.012s*/#include <cstdio>#include <cstring>int DNA[10], density[50][45];int main(void){int t, i, j;scanf("%d", &t);while (t--){for (i = 0; i < 10; i++)scanf("%d", &DNA[i]);memset(density, 0, sizeof(density));density[0][20] = 1;for (i = 1; i < 50; i++)for (j = 1; j < 41; j++)density[i][j] = DNA[density[i - 1][j - 1] + density[i - 1][j] + density[i - 1][j + 1]];for (i = 0; i < 50; i++){for (j = 1; j < 41; j++){switch (density[i][j]){ case 0:putchar(' ');break; case 1:putchar('.');break; case 2:putchar('x');break; default:putchar('W');//3}}putchar('\n');}if (t > 0) putchar('\n');}return 0;}
- UVa 457 Linear Cellular Automata (water ver.)
- UVa 457 - Linear Cellular Automata
- uva-457-Linear Cellular Automata
- UVA 457 - Linear Cellular Automata
- UVA 457 - Linear Cellular Automata
- UVA 457 - Linear Cellular Automata
- uva 457 Linear Cellular Automata
- UVa 457 - Linear Cellular Automata
- UVa 457 - Linear Cellular Automata
- UVA 457 Linear Cellular Automata
- UVA - 457 Linear Cellular Automata
- UVA-457-Linear Cellular Automata
- UVA - 457 Linear Cellular Automata
- uva Linear Cellular Automata
- UVA OJ 457 - Linear Cellular Automata
- UVa - 457 - Linear Cellular Automata 题解
- uva 457 Linear Cellular Automata(模拟)
- UVA - 457 Linear Cellular Automata(水题)
- 【OpenGL游戏开发之一】MAC OS X And Win7 vs2010 搭建OpenGL
- Android NDK 提供的交叉工具链手动编译源码
- HDU 1548 BFS 基础题
- Six_Training
- 二值形态学操作、图像的边缘检测、图像编码
- UVa 457 Linear Cellular Automata (water ver.)
- HDU--3068 最长回文 HDU(146)
- malloc/free与new/delete的区别 [转]
- 多进程读写锁
- A870省电内核&超频内核编译及制作
- Windows下载Android源码
- vc++加载透明png图片方法——GDI+和CImage两种 ,vs2005 vs2008 PNG背景
- 字符串中的每个单词倒序输出
- ubuntu安装.rpm文件