본문 바로가기

코딩테스트(백준)

[백준] 14503 : 로봇 청소기 - JAVA(자바) - 사좋배 공유

https://www.acmicpc.net/problem/14503

  

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
class robot{
	int x;
	int y;
	int dir;
	robot(int x, int y, int dir){
		this.x=x;
		this.y=y;
		this.dir=dir;
	}
	
}
public class Main {
	static int N;
	static int M;
	static int[][]arr;
	static int[]dx= {-1,0,1,0};
	static int[]dy= {0,1,0,-1};
	static int count;
	static Queue q;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N=sc.nextInt();
		M=sc.nextInt();
		arr=new int[N][M];
		int locationx=sc.nextInt();
		int locationy=sc.nextInt();
		int dir=sc.nextInt();
		q=new LinkedList();
		for(int i=0;i=N||ry>=M) {
					continue;
				}if(arr[rx][ry]==0) {
					q.add(new robot(rx,ry,dir));
					arr[rx][ry]=9;
					check=true;
					break;
				}
			}
			if(check==false) {
				int backdir=(dir+2)%4;
				int rx= x+dx[backdir];
				int ry= y+dy[backdir];
				if(arr[rx][ry]!=1) {
					arr[rx][ry]=9;
					q.add(new robot(rx,ry,dir));
				}
				
			}
		}
		
		
	}
}