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
- 백준 16935
- java 내림
- Codility
- 네트워크
- 자바
- 알고리즘
- sort
- 백준 17425
- 프로그래머스 도둑질 java
- 백준 4375
- time complexity
- 백준 15661
- 프로그래머스 숫자의 표현 java
- 백준 16927
- java 올림
- 백준 18290
- Math.floor()
- 프로그래머스 연속된 수의 합 java
- 코딩테스트
- java
- 백준 14391
- mysql
- 프로그래머스 네트워크 java
- Math.ceil()
- 프로그래머스 옹알이 java
- Algorithm
- Arrays
- 0으로 채우기
- java 반올림
- 백준 11723
Archives
- Today
- Total
취미처럼
[백준] 2529번 부등호 본문
https://www.acmicpc.net/problem/2529
2529번: 부등호
두 종류의 부등호 기호 ‘<’와 ‘>’가 k개 나열된 순서열 A가 있다. 우리는 이 부등호 기호 앞뒤에 서로 다른 한 자릿수 숫자를 넣어서 모든 부등호 관계를 만족시키려고 한다. 예를 들어, 제시
www.acmicpc.net
숫자 두개 비교했을 때 부등호가 참인 경우만 처리
import java.util.*;
import java.io.*;
public class Main {
public static int K;
public static char[] arr; // 부등호
public static boolean[] visit = new boolean[10]; // 0 ~ 9
public static List<String> ans = new ArrayList<>();
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
K = Integer.parseInt(st.nextToken());
arr = new char[K];
st = new StringTokenizer(br.readLine());
for(int i = 0; i < K; i++) {
arr[i] = st.nextToken().charAt(0);
}
dfs("", 0);
Collections.sort(ans);
// 최대값
System.out.println(ans.get(ans.size() - 1));
// 최소값
System.out.println(ans.get(0));
}
public static void dfs(String num, int depth) {
if(depth == K + 1 ) {
ans.add(num);
return;
}
for(int i = 0 ; i < 10; i++) {
// 첫번째 숫자인 경우 넘어감
// 첫번째 넘어갔으므로 arr[depth - 1]
if(depth == 0 || !visit[i] && compare(num.charAt(num.length()- 1) - '0', i, arr[depth - 1 ])) {
visit[i] = true;
dfs(num + i, depth + 1);
visit[i] = false;
}
}
}
public static boolean compare(int a, int b, char c) {
if(c == '<') {
return a < b;
} else {
return a > b;
}
}
}
'Algorithm > 백준' 카테고리의 다른 글
[백준] 10973번 이전 순열 (0) | 2021.03.04 |
---|---|
[백준] 10972번 다음 순열 (0) | 2021.03.04 |
[백준] 15661번 링크와 스타트 (0) | 2021.03.03 |
[백준] 14889번 스타트와 링크 (0) | 2021.03.03 |
[백준] 14501번 퇴사 (0) | 2021.03.03 |
Comments