Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class OcSenAnRau {
- static class toaDo
- {
- int x;
- int y;
- public toaDo(int x, int y)
- {
- this.x=x;
- this.y=y;
- }
- }
- static class Queue
- {
- final int size=100;
- toaDo [] q;
- int front, rear;
- //Constructor
- public Queue()
- {
- q=new toaDo[size];
- front=rear=-1;
- }
- public boolean isEmpty()
- {
- if(rear==front) return true;
- return false;
- }
- public void enQueue(toaDo a)
- {
- rear=(rear+1)%size;
- q[rear]=a;
- }
- public toaDo deQueue()
- {
- front=(front+1)%size;
- return q[front];
- }
- }
- public static int[]X= {-1,1,0,0};
- public static int[]Y= {0,0,-1,1};
- public static void main(String[] args) throws FileNotFoundException {
- System.setIn(new FileInputStream("D:\\Program\\STP\\senRau.txt"));
- Scanner sc=new Scanner(System.in);
- int m,n,res=1;
- m=sc.nextInt();
- n=sc.nextInt();
- int x=sc.nextInt();
- int y=sc.nextInt();
- int [][]A=new int[m][n];
- for(int i=0;i<m;i++)
- {
- for(int j=0;j<n;j++)
- {
- A[i][j]=sc.nextInt();
- }
- }
- Queue QQ=new Queue();
- A[x-1][y-1]=1;
- QQ.enQueue(new toaDo(x-1, y-1));
- while(!QQ.isEmpty())
- {
- toaDo tmpt=QQ.deQueue();
- for(int i=0;i<4;i++)
- {
- int u=tmpt.x+X[i];
- int v=tmpt.y+Y[i];
- if(u>=0&&u<m&&v>=0&&v<n&&A[u][v]==0)
- {
- res++;
- QQ.enQueue(new toaDo(u, v));
- A[u][v]=1;
- }
- }
- }
- System.out.println(res);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement