[ create a new paste ] login | about

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

hoaithu.melody - C++, pasted on Jun 26:
// BFS basic

package bfs;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Solution {
	
	static int front,rear,row,col;
	static int[] qr = new int[1000000], qc = new int[1000000];
	static int[][] a,visit;
	static int[] dirr= {-1,0,1,0},dirc= {0,1,0,-1};
	
	static void bfs(int rs,int cs , int re,int ce) {
		int r,c,nr,nc;
		front=0;rear=0;
		qr[rear] = rs; qc[rear] = cs; rear++;		
		visit[rs][cs] = 1;
		while(front !=rear) {
			r = qr[front];c=qc[front];front++;
			print(visit);
			if(r==re && c==ce) return;
			for(int i=0;i<4;i++) {
				nr = r+dirr[i];nc=c+dirc[i];				
				if(nr<0||nr>=row||nc <0||nc >= col|| visit[nr][nc] > 0 || a[nr][nc] == 0) continue;				
				visit[nr][nc] = visit[r][c] + 1;
				qr[rear]=nr;qc[rear]=nc;rear++;
			}
		}
	}
	
	static void print(int[][] mang) {
		for(int i=0;i<row;i++) {
			for(int j=0;j<row;j++) {
				System.out.print(mang[i][j] + " ");
			}
			System.out.println();
		}
		System.out.println();
	}
	
	public static void main(String[] args) throws FileNotFoundException {
		System.setIn(new FileInputStream("src/input.txt"));
		Scanner sc= new Scanner(System.in);
		
		row = sc.nextInt();
		col=row;
		a = new int[row+1][row+1];
		visit = new int[row+1][row+1];
		int rs,cs,re,ce;
		rs = sc.nextInt();
		cs=sc.nextInt();
		re=sc.nextInt();
		ce=sc.nextInt();
		for(int i=0;i<row;i++) {
			for(int j=0;j<row;j++) {
				a[i][j] = sc.nextInt();
			}
		}
		
		bfs(rs,cs,re,ce);
	}

}


Output:
1
2
Line 3: error: 'package' does not name a type
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: