본문 바로가기

나는 오늘,

(371)
좋은 수열 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class BOJ_2661 { static int n; static boolean flag = false; public static void main(String[] args) throws IOExc..
숨바꼭질4 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList..
자두나무 //dp 점화식으로도 풀어보기 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class ..
TapeEquilibrium 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 32 33 // you can also use imports, for example: // import java.util.*; // you can write to stdout for debugging purposes, e.g. // System.out.println("this is a debug message"); class Solution { public int solution(int[] A) { // write your code in Java SE 8 int total = 0; for (int i = 0; i
OddOccurencesInArray 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 // you can also use imports, for example: import java.util.*; // you can write to stdout for debugging purposes, e.g. // System.out.println("this is a debug message"); class Solution { public int solution(int[] A) { // write your code in Java SE 8 if (A.length == 1 ) return A[0]; Arrays.sort(A); //[2,2,2,4,5,5,4]-> 2,2..
Cyclic Rotation 두 가지 방법으로 풀 수 있다. (deque(덱), 배열을 하나씩 뒤로 밀고 맨 앞으로 맨 뒤의 요소를 삽입하는 것( O(k*n)) 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 import java.util.Deque; import java.util.ArrayDeque; import java.util.Iterator; class Solution { public int[] solution(int[] A, int k) { // write your code in Java SE 8 Deque dq = new ArrayDeque(); for (int i = 0; i 0) { if (dq.size() > 0) { dq.addF..
Binary Gap 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 class Solution { public int solution(int N) { // write your code in Java SE 8 boolean flag = false; int len = 0, max_len = 0; while(N > 0) { int binary = N % 2; if (binary == 1) { if (!flag) { flag = true; } else { //뒤쪽의 1을 만남 max_len = max_len
사탕상자 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 #include #include #include #define MAXX 1000001 using namespace std; typedef long long ll; int tree_h; int ret = 0; void update(vector &tree, int node, int diff, int idx, in..