[ create a new paste ] login | about

Link: http://codepad.org/nCnqWWa1    [ raw code | fork ]

hoaithu.melody - C++, pasted on Jun 20:
// Laughing bomb c++

#include <iostream>


using namespace std;

int TC, N, M, A[102][102], visit[102][102], stx, sty;

int Q[1000000];
int l, r;

int pop(){
	return Q[++l];
}

void push(int n){
	Q[++r]=n;;
}

int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};

int main(){
	//freopen("in.txt", "r", stdin);
	
	cin>>TC;
	for(int t=1; t<=TC; t++){
		l=r=-1;
		int count=0;
		cin>>M>>N;
		for(int i=1; i<=N; i++){
			for(int j=1; j<=M; j++){
				cin>> A[i][j];
				visit[i][j]=0;
			}
		}
		cin>>sty>>stx;
		push(stx*1000+sty);
		visit[stx][sty]=1;
		while(l!=r){
			int tmp=pop();
			int x=tmp/1000;
			int y=tmp%1000;
			for(int i=0; i<4; i++){
				int xN= x+dx[i];
				int yN= y+dy[i];
				if(xN>0 && xN<=N && yN>=1 && yN<=M){
					if(A[xN][yN]==1 && visit[xN][yN]==0 ){
						push(xN*1000+yN);
						visit[xN][yN]=visit[x][y]+1;
						count=visit[xN][yN];
					}
				}
			}
		}
		
		
		cout<< count<<endl;
	}
	
	return 0;
}


Output:
No errors or program output.


Create a new paste based on this one


Comments: