1091. Acute Stroke (30)

这题贼坑,我也是看了别人的博客提示才弄出来的
1.理解题意,大概是要求联通的1的个数大于T的区域有多少,联通的三维的联通(6个方向)
2.不能用递归的DFS,测试案例里联通区域有几十万这么大,用递归系统的栈会溢出的,最后5分会过不去,用BFS就能过了
#include<iostream>
#include<algorithm>
#include<string>
using namespace std; 
short  V[62][1300][130];
short  isread[62][1300][130];
struct BFS{
int t1,t2,t3;	
}B[10000000];
int N,M,L,T,coo,top=0,end1=0;
void GetLevel(BFS s){	
	BFS temp,t;
	isread[s.t1][s.t2][s.t3]=1;
	B[top++]=s;
	while(top!=end1){
		t=B[end1++];coo++;
		int a=t.t1,b=t.t2,c=t.t3;
		
	if(isread[a-1][b][c]==0&&V[a-1][b][c]==1){
		temp=t;
		temp.t1--;
		isread[temp.t1][temp.t2][temp.t3]=1;
		B[top++]=temp;
	}
	if(isread[a+1][b][c]==0&&V[a+1][b][c]==1){
		temp=t;
		temp.t1++;
		isread[temp.t1][temp.t2][temp.t3]=1;
		B[top++]=temp;
	}
	if(isread[a][b-1][c]==0&&V[a][b-1][c]==1){
		temp=t;
		temp.t2--;
		isread[temp.t1][temp.t2][temp.t3]=1;
		B[top++]=temp;
	}
	if(isread[a][b+1][c]==0&&V[a][b+1][c]==1){
		temp=t;
		temp.t2++;
		isread[temp.t1][temp.t2][temp.t3]=1;
		B[top++]=temp;
	}
	if(isread[a][b][c-1]==0&&V[a][b][c-1]==1){
		temp=t;
		temp.t3--;
		isread[temp.t1][temp.t2][temp.t3]=1;
		B[top++]=temp;
	}
	if(isread[a][b][c+1]==0&&V[a][b][c+1]==1){
		temp=t;
		temp.t3++;
		isread[temp.t1][temp.t2][temp.t3]=1;
		B[top++]=temp;
	}
	}
}
int main(){
	int i,j,k,count=0,temp;
	BFS s;
	cin>>M>>L>>N>>T;
	for(i=0;i<=N+1;i++)
	for(j=0;j<=M+1;j++)
	for(k=0;k<=L+1;k++){
		V[i][j][k]=0; 
	} 
	for(i=1;i<=N;i++)
	for(j=1;j<=M;j++)
	for(k=1;k<=L;k++){
		scanf("%d",&V[i][j][k]);	
	}
	for(i=1;i<=N;i++)
	for(j=1;j<=M;j++)
	for(k=1;k<=L;k++){
		if(isread[i][j][k]==0&&V[i][j][k]==1){
			coo=0;
			s.t1=i;
			s.t2=j;
			s.t3=k;
			top=0;
			end1=0;
			GetLevel(s);
			if(coo>=T)
			count+=coo;
		}
	}
	cout<<count;
} 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值