Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.5 kB
7
Indexable
Never
#include <iostream>
#include <stdio.h>
using namespace std;
int n, m, vtdx, vtdy, tl;
int datag[1001][1001];
int dataf[3001][3001];
int visitf[3001][3001];
int front, rear;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
int data1[24][3] = {{0,0,0},{0,0,0},{0,0,0},
                    {0,1,0},{1,1,1},{0,1,0},
                    {0,1,0},{0,1,0},{0,1,0},
                    {0,0,0},{1,1,1},{0,0,0},
                    {0,1,0},{0,1,1},{0,0,0},
                    {0,0,0},{0,1,1},{0,1,0},
                    {0,0,0},{1,1,0},{0,1,0},
                    {0,1,0},{1,1,0},{0,0,0}};

void init() {
	front = 0;
	rear = 0;
}

struct toado
{ int x, y;
};

toado queu[100000];

void push(int xx, int yy) {
	queu[rear].x = xx;
	queu[rear].y = yy;
	rear ++;
}

toado pop() {
	toado t = queu[front];
	front ++;
	return t;
}

int BFS(int x, int y, int tl) {
	init();
	int dem = 1;
	push(x, y);
	visitf[x][y] = 1;
	while (front < rear) {
		toado vitri = pop();
		for (int i = 0; i < 4; i++) {
			int xn = vitri.x +dx[i];
			int yn = vitri.y +dy[i];
			if (xn >= 0 && xn < 3*n && yn >= 0 && yn < 3*m && dataf[xn][yn] == 1 && visitf[xn][yn] == 0 ) {
				push(xn,yn);
				visitf[xn][yn] = visitf[vitri.x][vitri.y] + 1;
				if (visitf[xn][yn] % 3 == 1) dem ++;
				if (visitf[xn][yn] == tl+1) front = rear;

			}
		}
		
	}
	return dem;
}

int main() {
	freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);
	int sl;
	cin >> sl;
	for (int stt = 1; stt <= sl; stt++) {
		cin >> n >> m >> vtdx >> vtdy >> tl;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				datag[i][j] = 0;	
			}
		}

		for (int i = 0; i < 3*n-1; i++) {
			for (int j = 0; j < 3*m-1; j++) {
				dataf[i][j] = 0;
				visitf[i][j] = 0;
			}
		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cin >> datag[i][j];
			}
		}

		 for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				int giatri = datag[i][j]; 
				for (int xx = i*3; xx < i*3+3; xx++) {
					for (int yy = j*3; yy < j*3+3; yy++) {
						dataf[xx][yy] = data1[giatri*3 + xx-i*3][yy-j*3];
					}
				}

			}
		} 
         tl = 2 + (tl-1) * 3;
		 int t = BFS(vtdx*3 + 1, vtdy*3 + 1, tl);


		/* for (int i = 0; i < 3*n-1; i++) {
			for (int j = 0; j < 3*m-1; j++) {

				cout << visitf[i][j]<<" "; 
			}cout <<endl;
		}*/

		cout <<"Case #"<<stt<<endl;
		cout << t<<endl;
	


	}
	return 0;
}