码迷,mamicode.com
首页 > 其他好文 > 详细

HDOJ1057 A New Growth Industry 【模拟】

时间:2014-05-13 14:37:18      阅读:354      评论:0      收藏:0      [点我收藏+]

标签:hdoj1057

A New Growth Industry

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1197    Accepted Submission(s): 474


Problem Description
bubuko.com,布布扣

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
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
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:

bubuko.com,布布扣

No other characters may appear in the output.
 

Sample Input
1 2 0 1 1 1 2 1 0 -1 -1 -1 -2 -2 -3 -3 -3 -3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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>
int arr[22][22], temp[22][22], d[17];
char sign[] = {‘.‘, ‘!‘, ‘X‘, ‘#‘};

int main(){
	int t, n, k;
	scanf("%d", &t);
	while(t--){
		scanf("%d", &n);
		for(int i = 0; i < 16; ++i)
			scanf("%d", &d[i]);
		for(int i = 1; i < 21; ++i)
			for(int j = 1; j < 21; ++j)
				scanf("%d", &arr[i][j]);			
		while(n--){
			for(int i = 1; i < 21; ++i)
				for(int j = 1; j < 21; ++j){
					k = arr[i][j] + arr[i][j+1] + 
						arr[i][j-1] + arr[i-1][j] + arr[i+1][j];
					temp[i][j] = arr[i][j] + d[k];
					if(temp[i][j] < 0) temp[i][j] = 0;
					else if(temp[i][j] > 3) temp[i][j] = 3;
				}
			for(int i = 1; i < 21; ++i)
				for(int j = 1; j < 21; ++j) arr[i][j] = temp[i][j];
		}
		for(int i = 1; i < 21; ++i){
			for(int j = 1; j < 21; ++j)
				putchar(sign[arr[i][j]]);			
			putchar(‘\n‘);
		}
		if(t) putchar(‘\n‘);
	}
	return 0;
}


HDOJ1057 A New Growth Industry 【模拟】,布布扣,bubuko.com

HDOJ1057 A New Growth Industry 【模拟】

标签:hdoj1057

原文地址:http://blog.csdn.net/chang_mu/article/details/25659131

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!