UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#197978#1179. 细菌的繁殖与扩散noi_yangge1001ms1200kbC++1.5kb2023-11-16 15:57:562023-11-16 15:57:57

answer

#include<iostream>
using namespace std;
int a[9][9], b[9][9];
//输出
void output(int a[][9]) {
	for (int i = 0; i < 9; i++) {
		int j = 0;
		for (; j < 8; j++) {
			cout << a[i][j] << " ";
		}
		cout << a[i][j] << endl;
	}
}
//一天繁殖,题目给的最大繁殖天数为4;由内往外繁殖,子细菌不会出现在矩阵外的,故非0侧边一定能到达的,不再用if判断
void repro(int old[][9], int gener[][9]) {
	fill(gener[0], gener[0] + 81, 0);
	for (int i = 0; i < 9; i++) {
		for (int j = 0; j < 9; j++) {
			if (old[i][j] != 0) {
				//左侧
				gener[i][j - 1] += old[i][j];
				//左上
				gener[i - 1][j - 1] += old[i][j];

				//左下
				gener[i + 1][j - 1] += old[i][j];
				//右侧
				gener[i][j + 1] += old[i][j];
				//右上
				gener[i - 1][j + 1] += old[i][j];
				//右下
				gener[i + 1][j + 1] += old[i][j];
				//上侧
				gener[i - 1][j] += old[i][j];
				//下侧
				gener[i + 1][j] += old[i][j];
				//务必用加等号,不能直接用等。因为同坐标的新位置处完全有可能已经有了前面繁殖来的子细菌。该位置细菌数为原来2倍
				gener[i][j] += 2 * old[i][j];
			}
		}
	}
}

int main()
{
	int d;
	//freopen("in.txt", "r", stdin);
	cin >> a[4][4] >> d;
	for (int t = 1; t <= d; t++) {
		//旧新矩阵
		if (t % 2 == 1) {
			repro(a, b);
		}
		else {
			repro(b, a);
		}
	}
	//选择输出矩阵
	if (d % 2 == 1) {
		output(b);
	}
	else {
		output(a);
	}

	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1196kb

input:

12 3

output:

0 0 0 0 0 0 0 0 0
0 12 36 72 84 72 36 12 0
0 36 144 288 360 288 144 36 0
0 72 288 612 756 612 288 72...

result:

ok 9 lines

Test #2:

score: 10
Accepted
time: 0ms
memory: 1196kb

input:

29 3

output:

0 0 0 0 0 0 0 0 0
0 29 87 174 203 174 87 29 0
0 87 348 696 870 696 348 87 0
0 174 696 1479 1827 1479...

result:

ok 9 lines

Test #3:

score: 10
Accepted
time: 0ms
memory: 1200kb

input:

27 1

output:

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 27 27 27 0 0 0
0 0 0 27 54 27 0 0 0
0 0 ...

result:

ok 9 lines

Test #4:

score: 10
Accepted
time: 1ms
memory: 1196kb

input:

26 1

output:

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 26 26 26 0 0 0
0 0 0 26 52 26 0 0 0
0 0 ...

result:

ok 9 lines

Test #5:

score: 10
Accepted
time: 0ms
memory: 1200kb

input:

21 2

output:

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 21 42 63 42 21 0 0
0 0 42 126 168 126 42 0 0
0 0 63 168 252 ...

result:

ok 9 lines

Test #6:

score: 10
Accepted
time: 0ms
memory: 1200kb

input:

5 3

output:

0 0 0 0 0 0 0 0 0
0 5 15 30 35 30 15 5 0
0 15 60 120 150 120 60 15 0
0 30 120 255 315 255 120 30 0
0...

result:

ok 9 lines

Test #7:

score: 10
Accepted
time: 0ms
memory: 1200kb

input:

8 3

output:

0 0 0 0 0 0 0 0 0
0 8 24 48 56 48 24 8 0
0 24 96 192 240 192 96 24 0
0 48 192 408 504 408 192 48 0
0...

result:

ok 9 lines

Test #8:

score: 10
Accepted
time: 0ms
memory: 1196kb

input:

23 1

output:

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 23 23 23 0 0 0
0 0 0 23 46 23 0 0 0
0 0 ...

result:

ok 9 lines

Test #9:

score: 10
Accepted
time: 0ms
memory: 1196kb

input:

7 2

output:

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 7 14 21 14 7 0 0
0 0 14 42 56 42 14 0 0
0 0 21 56 84 56 21 0...

result:

ok 9 lines

Test #10:

score: 10
Accepted
time: 0ms
memory: 1196kb

input:

4 1

output:

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 4 4 4 0 0 0
0 0 0 4 8 4 0 0 0
0 0 0 4 4 ...

result:

ok 9 lines