1051_A New Growth Industry
来源:互联网 发布:在北京做程序员好吗 编辑:程序博客网 时间:2024/05/16 07:47
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 Format:
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 Format:
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:
No other characters may appear in the output.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Sample Input:
120 1 1 1 2 1 0 -1 -1 -1 -2 -2 -3 -3 -3 -33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Sample Output:
##!.................#!..................!............................................................................................................!..................!#!................!#X#!................!#!..................!..........................................................................................................................................................................
**********************************************************************************************************************************************************
#include<iostream>#include<string>using namespace std;int main(){ string ss(".!X#");const int max=20;int count;int days;//模拟几天int rule[16];int square[max][max],trans[max][max];//trans[][]用于过渡,因为square[][]的一个元素处理过后,隔壁元素还要用未出理前的那个元素int num;cin>>count;while(count--){cin>>days;for(int i=0;i!=16;i++)cin>>rule[i];for(int i=0;i!=max;i++)for(int j=0;j!=max;j++)cin>>square[i][j];while(days--){for(int i=0;i!=max;i++)for(int j=0;j!=max;j++){num=square[i][j];if(j-1>=0)//临界检测num+=square[i][j-1];if(i-1>=0)num+=square[i-1][j];if(j+1<max)num+=square[i][j+1];if(i+1<max)num+=square[i+1][j];trans[i][j]=square[i][j]+rule[num];//处理if(trans[i][j]<0)trans[i][j]=0;if(trans[i][j]>3)trans[i][j]=3;}for(int i=0;i!=max;i++)for(int j=0;j!=max;j++) square[i][j]=trans[i][j];}for(int i=0;i!=max;i++){for(int j=0;j!=max;j++)cout<<ss[square[i][j]];cout<<endl;}if(count!=0)//每个测试隔一行,最后一个后面就没有 cout<<endl;}return 0;}
- 1051_A New Growth Industry
- ZOJ 1051 A New Growth Industry
- ZOJ 1051 A New Growth Industry
- HDU 1051 A New Growth Industry
- ZOJ 1051 A New Growth Industry
- zoj 1051 A New Growth Industry
- zoj 1051 A New Growth Industry
- zoj 1051 A New Growth Industry
- ZOJ_1051_A New Growth Industry
- A New Growth Industry
- zoj1051 A New Growth Industry
- ZOJ1051 A New Growth Industry
- JOJ1086: A New Growth Industry
- ZOJ1051 A New Growth Industry
- ZOJ1051 A New Growth Industry
- Zoj1051 A New Growth Industry
- ZOJ Problem Set - 1051 A New Growth Industry
- zoj1051--------A New Growth Industry 细菌~
- Spring 3.1MVC 实战
- 鉴客 Android 背景图片重复 Background repeat
- Reflector 已经out了,试试ILSpy
- Air Mobile As3 App
- 国际著名黑客大赛介绍与比较
- 1051_A New Growth Industry
- 破那个垃圾安全狗技术总汇
- ORA-00093: pga_aggregate_target must be between 10M and 4096G-1
- 1049_I Think I Need a Houseboat
- 卷积和积分运算
- C#static
- 内部类总结
- android viewanimator viewfilter viewswitcher textswitcher imageswitcher
- 1048_Financial Management