uva457 Linear Cellular Automata
来源:互联网 发布:qt 关闭release优化 编辑:程序博客网 时间:2024/04/29 22:23
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'.
读题 花了很长时间,题目本身不难,注意最后一个case不需要换行符,就是说一个case时不要输出换行,候否则判错,在这wrong了几次。
#include <stdio.h>#include <string.h>int dish[41], t[41], DNA[10];int main(){ int tcase; scanf("%d", &tcase); while (tcase--) { int i, j; memset(dish, 0, sizeof(dish)); dish[19] = 1; for (i = 0; i < 10; i++) scanf("%d", &DNA[i]); for (i = 0; i < 50; i++) { for (j = 0; j < 40; j++) { t[j] = dish[j]; switch (dish[j]) { case 0: putchar(' '); break; case 1: putchar('.'); break; case 2: putchar('x'); break; default: putchar('W'); } } putchar('\n'); for (j = 1; j < 40; j++) dish[j] = DNA[t[j-1] + t[j] + t[j + 1]]; dish[0] = DNA[t[0] + t[1]]; } if (tcase > 0) putchar('\n'); } return 0;}
- uva457 Linear Cellular Automata
- uva457 - Linear Cellular Automata
- UVa457 Linear Cellular Automata
- UVA457 - Linear Cellular Automata
- UVa457 - Linear Cellular Automata-字符串-难度1
- Linear Cellular Automata
- 457 - Linear Cellular Automata
- 457 - Linear Cellular Automata
- 457 - Linear Cellular Automata
- 457 - Linear Cellular Automata
- 457 - Linear Cellular Automata
- Linear Cellular Automata
- Linear Cellular Automata
- Linear Cellular Automata
- Linear Cellular Automata
- 457 - Linear Cellular Automata
- uva Linear Cellular Automata
- 457 - Linear Cellular Automata
- Linux shell脚本中判断变量文件目录:权限、是否存在、空值、相等
- C++的64位整数[原]by 赤兔
- MySQL 引擎 概述
- Linux汇编写引导扇区
- 文章统计日点击、周点击、月点击制作思路(存储过程实现)
- uva457 Linear Cellular Automata
- 【模拟】使用蒙特卡罗算法计算圆周率
- linux2.6 内核的 initrd
- 研发部经理(研发总监)
- 深入理解socket select模型
- JAVA基础:Java运算符大百科
- 纪念一下首个自己搭建起来的ftp(非技术)
- JAVA 位操作详解
- c/c++编写window服务的授权服务(一)