A1091 Acute Stroke

#include<iostream>
#include<queue>
#include<stdio.h>
using namespace std;
int M,N,L,T;
struct node{
	int x,y,z;
}Node;
int X[6] = {0, 0,-1,1,0,0};//上下左右前後 
int Y[6] = {0, 0, 0,0,1,-1};
int Z[6] = {1,-1, 0,0,0,0};
int p[61][1290][130];
bool inq[61][1290][130] ={false};
int ans = 0;
int BFS(int z,int x,int y){
	int Sum = 1;
	queue<node> q;
	Node.x = x;
	Node.y = y;
	Node.z = z;
	q.push(Node);
	while(!q.empty()){
		node top = q.front();
		q.pop();
		for(int i =0;i<6;i++){	
			Node.x = top.x + X[i];
			Node.y = top.y + Y[i];
			Node.z = top.z + Z[i];
			if(Node.x>=0&&Node.x<M&&Node.y>=0&&Node.y<N&&Node.z>=0&&Node.z<L&&p[Node.z][Node.x][Node.y]==1&&inq[Node.z][Node.x][Node.y]==false){
				Sum++;
				q.push(Node);
				inq[Node.z][Node.x][Node.y]=true;
			}
		}
	}
	return Sum;
}
int main(){
	//freopen("in.txt","r",stdin);
	cin>>M>>N>>L>>T;      
	for(int t = 0;t<L;t++){
		for(int i = 0;i<M;i++){
			for(int j = 0;j<N;j++){
				scanf("%d",&p[t][i][j]);
			}
		}
	}
	for(int t = 0;t<L;t++){
		for(int i = 0;i<M;i++){
			for(int j = 0;j<N;j++){
				if(p[t][i][j]==1&&inq[t][i][j]==false){
					inq[t][i][j] = true;
					int temp = BFS(t,i,j);
					if(temp >=T){
						ans += temp;
					}			
				}
			}
		}
	}
	cout<<ans<<'\n'; 
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章