목록분류 전체보기 (273)
Dev.baelanche
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/oXqy5/btqwYipovAI/e9fA0kRPzKok5FL47Gsduk/img.png)
정~~~~말 간만에 스위치로 구현한 문제라서 업로드했다. 기본 문자열 다루는 문제라서 따로 설명할건 없고 소스코드를 보면 될 것 같다. public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); char c[][] = new char[n][n]; for(int i=0; i
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/tWMAn/btqw0mcQzFt/2zIMmqjgKy4BcsxtKAZn2k/img.png)
명령어의 수가 최대 1000이므로 2000*2000의 배열공간만 있으면 모든 경우를 저장할 수 있다. 한번이라도 가본 좌표를 체크해주기만 하면 된다. public class Main { static int l; static char c[]; static boolean visited[][] = new boolean[2001][2001]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); l = sc.nextInt(); c = sc.next().toCharArray(); dfs(1000, 1000, 0); int cnt = 0; for(int i=0; i
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/8LhUU/btqw0ItctBq/ycorJLYQPaY1nbyxsO0IxK/img.png)
N, M 이 최대 10으로 충분히 작기 때문에 완전탐색으로 문제를 풀 수 있다. 백트래킹으로 모든 경우를 되집어보며 구해주었다. public class Main { static int n; static int m; static int a[][]; static boolean visited[]; static int min = Integer.MAX_VALUE; public static void main(String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); m = sc.nextInt(); a = new int[11][11]; visited = new boolean[11]; for(int i=1; i0) { a[i][sc.nextInt()..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/bzGzO3/btqwVfzzipo/b5CCciHO7BckvKUuwGInvk/img.png)
구현자체는 정말 쉬운 문제다. for(int i=0; i0) { st = new StringTokenizer(br.readLine()); a = Integer.parseInt(st.nextToken()); b = Integer.parseInt(st.nextToken()); ch = br.readLine().toCharArray(); len = ch.length; for(int i=0; i
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/cP9sjj/btqwWZ22FS7/Z3hdlmphvCCpnNZbTeKEh1/img.png)
문제에서 서술해준 대로 GCD = 1, LCM = A*B 인 경우를 찾아서 카운트한다. N = 30 일때 완전탐색으로 (1, 30), (2, 15), (3, 10), (5, 6), (6, 5), (10, 3), (15, 2), (30, 1) 을 찾을 수 있다. 총 개수/2 를 하게되면 N이 큰 수 일때 TLE 가 발생한다. (5, 6) => (6, 5) 로 넘어갈때 오른쪽수보다 왼쪽수가 더 커지게 된다. 이 부분을 체크하여 시간초과를 해결해 주었다. public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int n = s..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/cJ43ke/btqwVUBDyMz/2pVST7igwqUIbXW6kzdkfk/img.png)
점 a, b, c 를 완적탐색으로 하면 O(n^3)으로 시간초과가 나게 된다. 점 a, b 를 고르고 이분탐색으로 c를 찾으면 O(n^2 log n)으로 AC를 맞을 수 있지만 O(n^2)의 방법으로 풀어보겠다. 점 a, b 를 정하고 b-a와 같은 값 c를 b < k < n 에서 찾는다. k == n-1 일때까지 모두 탐색했다면 b를 오른쪽 점으로 한칸 옮겨서 반복 수행한다. a점도 마찬가지로 b점이 b == n-2 이면 오른쪽으로 움직인다. public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.i..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/PJ4H4/btqwUDACEyN/xRJbFp70KumKCI3oHIoNK1/img.png)
예제를 예로 설명해보겠다. 입력값 배열 3 4 7 5 6 4 2 9 입력값따로, 부분합배열을 따로 만들어준다. 부분합 배열 3 7 14 19 25 29 31 40 43 47 for(int i=1; i0) { int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); int a[] = new int[n]; for(int i=0; i
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/yixIT/btqwVhc0KD0/2ieHaXEZ0GU8huaObAEIh0/img.png)
문자열체크 문제이다. +, -, *, / 가 나오기 전까지의 문자들을 왼쪽 숫자, 그 이후부터 = 이전까지의 문자들을 오른쪽 숫자 = 이후의 문자들을 결과값으로 저장한다. 왼쪽 숫자가 음수일 수 있으므로 그 부분을 유의해야한다. public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); sc.nextLine(); while(t-->0) { char c[] = sc.nextLine().replaceAll(" ", "").toCharArray(); String left = ""; char mid; String right = ""; String result..