일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 큐
- OOB
- off by one
- 백트래킹
- 연결리스트
- 분할 정복
- syscall
- 투 포인터
- 완전 탐색
- RTL
- 이분 탐색
- 스위핑 알고리즘
- 포맷스트링버그
- 에라토스테네스의 체
- fsb
- 이진트리
- House of Orange
- 수학
- 브루트 포스
- 문자열 처리
- BOF
- DFS
- 이진 탐색
- BFS
- 동적 계획법
- tcache
- heap
- 다이나믹 프로그래밍
- 스택
- ROP
Archives
- Today
- Total
SDJ( 수돈재 아님 ㅎ )
[Java] 8911 - 거북이 본문
문제 링크 : https://www.acmicpc.net/problem/8911
8911번: 거북이
문제 상근이는 2차원 평면 위에서 움직일 수 있는 거북이 로봇을 하나 가지고 있다. 거북이 로봇에게 내릴 수 있는 명령은 다음과 같이 네가지가 있다. F: 한 눈금 앞으로 B: 한 눈금 뒤로 L: 왼쪽��
www.acmicpc.net
JAVA공부한겸 한번 객체로 만들어서 풀어보고싶어서 끄적거리면서 풀어본 문제
아직 뭐가 뭐하는놈인지 몰라서 일단 작성하고봤는데 빨리 익숙해져야할듯
import java.util.*;
public class Main {
static class turtle{
private int x;
private int y;
private int MAX_X;
private int MAX_Y;
private int MIN_X;
private int MIN_Y;
private int[][] dir;
private int[] cur;
private int idx;
public turtle() {
this.x = 0;
this.y = 0;
this.MAX_X = 0;
this.MAX_Y = 0;
this.MIN_X = 0;
this.MIN_Y = 0;
this.idx = 0;
this.dir = new int[][] {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
this.cur = dir[idx];
}
public void F() {
this.x += cur[0];
this.y += cur[1];
if(this.MAX_X < this.x)
this.MAX_X = this.x;
else if(this.x < this.MIN_X)
this.MIN_X = this.x;
if(this.MAX_Y < this.y)
this.MAX_Y = this.y;
else if(this.y < this.MIN_Y)
this.MIN_Y = this.y;
}
public void B() {
this.x -= cur[0];
this.y -= cur[1];
if(this.MAX_X < this.x)
this.MAX_X = this.x;
else if(this.x < this.MIN_X)
this.MIN_X = this.x;
if(this.MAX_Y < this.y)
this.MAX_Y = this.y;
else if(this.y < this.MIN_Y)
this.MIN_Y = this.y;
}
public void L() {
this.idx = (this.idx+1)%4;
this.cur = dir[idx];
}
public void R() {
this.idx = ((this.idx-1)%4 >= 0 ? (this.idx-1)%4 : 3);
this.cur = dir[idx];
}
public int end() {
return Math.abs((this.MAX_Y-this.MIN_Y)*(this.MAX_X-this.MIN_X));
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T;
String command = "";
T = sc.nextInt();
while(T != 0)
{
turtle Turtle = new turtle();
command = sc.next();
for(int i = 0; i < command.length(); ++i)
{
if(command.charAt(i) == 'F')
Turtle.F();
else if(command.charAt(i) == 'B')
Turtle.B();
else if(command.charAt(i) == 'L')
Turtle.L();
else if(command.charAt(i) == 'R')
Turtle.R();
}
System.out.println(Turtle.end());
T -= 1;
}
}
}
'알고리즘 > Backjoon' 카테고리의 다른 글
[C++] 17267 - 상남자 (0) | 2020.07.01 |
---|---|
[C++] 1013 - Contact (0) | 2020.06.30 |
[C] 1021 - 회전하는 큐 (0) | 2020.06.30 |
[C++] 12904 - A와 B (0) | 2020.06.30 |
[C++] 1806 - 부분합 (0) | 2020.02.01 |
Comments