Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 29 | 30 |
| 31 |
Tags
- 러닝일지
- 코딩테스트
- binary search
- DP
- 자바
- MySQL
- 투포인터
- dfs
- SWEA
- 문제해결
- 시뮬레이션
- math
- 운동기록
- SQL
- greedy
- oracle
- BOJ
- Java
- priorityqueue
- 이분탐색
- 백준
- COS PRO
- db
- 문제풀이
- 건강
- BFS
- 프로그래머스
- 코테
- 문자열
- 알고리즘
Archives
- Today
- Total
슈콩
[SWEA] 신뢰 본문

[문제]
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXSVc1TqEAYDFAQT#none
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
[소스 코드]
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int T = Integer.parseInt(br.readLine());
for(int tc=1;tc<=T;tc++) {
st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
Queue<String> robot = new LinkedList<>();
Queue<Integer> orange = new LinkedList<>();
Queue<Integer> blue = new LinkedList<>();
for(int i=0;i<n;i++) {
String color = st.nextToken();
robot.offer(color);
int x = Integer.parseInt(st.nextToken());
if(color.equals("O")) orange.offer(x);
else blue.offer(x);
}
int result = 0;
int oP = 1;
int bP = 1;
while(!robot.isEmpty()) {
boolean push = false;
if(!orange.isEmpty()) {
int oPos = orange.peek();
if(oPos>oP) oP++;
else if(oPos<oP) oP--;
else {
if(!push && robot.peek().equals("O")) {
push = true;
robot.poll();
orange.poll();
}
}
}
if(!blue.isEmpty()) {
int bPos = blue.peek();
if(bPos>bP) bP++;
else if(bPos<bP) bP--;
else {
if(!push && robot.peek().equals("B")) {
push = true;
robot.poll();
blue.poll();
}
}
}
result++;
}
System.out.println("#"+tc+" "+result);
}
}
}'Algorithms > SWEA' 카테고리의 다른 글
| [SWEA] 공평한 분배 2 (0) | 2025.11.15 |
|---|---|
| [SWEA] 사랑의 카운슬러 (0) | 2025.11.15 |
| [SWEA] 알파벳 공부 (0) | 2025.11.14 |
| [SWEA] 힙 (0) | 2025.11.14 |
| [SWEA] 제로 (0) | 2025.11.14 |