Skip to content

0926 송예림 2문제 #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions 송예림/Week26/BOJ_gold4_2310_어드벤처게임.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package BAEKJOON;

import java.io.*;
import java.util.*;

public class gold4_2310_어드벤처게임 {
static int n;
static boolean check;
static boolean[] visit;
static ArrayList<Integer>[] list;
static Room[] room;

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
StringBuilder sb = new StringBuilder();

while(true) {
check = false;
n = Integer.parseInt(br.readLine());

if(n == 0) break;

visit = new boolean[n];
list = new ArrayList[n];
room = new Room[n];

for (int i = 0; i < n; i++) {
list[i] = new ArrayList<>();
st = new StringTokenizer(br.readLine());
room[i] = new Room(st.nextToken().charAt(0), Integer.parseInt(st.nextToken()));
while(true) {
int p = Integer.parseInt(st.nextToken());
if(p == 0) break;
list[i].add(p-1);
}
}

// 이동할 수 있는 방 확인해서 이동하기
// 확인할 때 L, E이면 가능 T면 조건 확인
// 무한루프돌수도???????
/*
* L 한정해서 방문배열 적용안하고 L 금액보다 작으면 탐색 가능하게 해주기
*/
int curPrice = 0;
if(room[0].type == 'T') {
sb.append("No\n");
continue;
} else if(room[0].type == 'L') {
curPrice += room[0].price;
} else {
visit[0] = true;
}

move(0, curPrice);

if(check) {
sb.append("Yes\n");
} else {
sb.append("No\n");
}
}

System.out.println(sb);
}

private static void move(int curRoom, int curPrice) {
if(curRoom == n-1) {
check = true;
return;
}

// 다음 방 탐색
for (int i = 0; i < list[curRoom].size(); i++) {
int idx = list[curRoom].get(i);
if(room[idx].type == 'T') {
if(!visit[idx] && curPrice >= room[idx].price) {
visit[idx] = true;
move(idx, curPrice - room[idx].price);
visit[idx] = false;
}
} else if(room[idx].type == 'L') {
if(visit[idx] && curPrice < room[idx].price) {
move(idx, room[idx].price);
} else if(!visit[idx]) {
visit[idx] = true;
move(idx, curPrice > room[idx].price ? curPrice : room[idx].price);
visit[idx] = false;
}
} else {
if(!visit[idx]) {
visit[idx] = true;
move(idx, curPrice);
visit[idx] = false;
}
}
}
}

static class Room {
char type;
int price;

public Room(char type, int price) {
this.type = type;
this.price = price;
}
}
}
59 changes: 59 additions & 0 deletions 송예림/Week26/BOJ_silver2_27497_알파벳블록.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package BAEKJOON;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.Stack;
import java.util.StringTokenizer;

public class silver2_27497_알파벳블록 {

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
StringBuilder sb = new StringBuilder();
Stack<Integer> stk = new Stack<>(); // 앞이면 2 뒤면 1
ArrayDeque<String> dq = new ArrayDeque<>();
int N = Integer.parseInt(br.readLine());

for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
int num = Integer.parseInt(st.nextToken());
if(num == 3) {
if(stk.isEmpty()) continue;
int tmp = stk.pop();
if(tmp == 2) {
dq.poll();
} else {
dq.pollLast();
}
continue;
}
String ch = st.nextToken();
switch(num) {
case 1:
stk.add(num);
dq.offer(ch);
break;
case 2:
stk.add(num);
dq.offerFirst(ch);
break;
case 3:

}
}

if(dq.isEmpty()) {
System.out.println(0);
return;
}
for (String s : dq) {
sb.append(s);
}

System.out.println(sb);
}

}