diff --git a/boj/ashsty/week2/1461.java b/boj/ashsty/week2/1461.java new file mode 100644 index 0000000..38ccd90 --- /dev/null +++ b/boj/ashsty/week2/1461.java @@ -0,0 +1,61 @@ +import java.util.*; +import java.io.*; + +public class Main{ + + static int max=0; + static int n; + static int countPlus=0; + static int countMinus=0; + static int count = 0; + static List plus; + static List minus; + + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + StringTokenizer str1 = new StringTokenizer(br.readLine()); + + int m = Integer.parseInt(str1.nextToken()); + n = Integer.parseInt(str1.nextToken()); + + plus=new ArrayList<>(); + minus=new ArrayList<>(); + + StringTokenizer str2 = new StringTokenizer(br.readLine()); + + for(int i=0; i=0){ + plus.add(num); + } + else{ + minus.add(Math.abs(num)); + } + } + + Collections.sort(plus); + Collections.sort(minus); + + greedySejun(plus); + greedySejun(minus); + + System.out.println(count - max); + } + + private static void greedySejun(List array){ + int flag = array.size() % n; + int i = array.size() - 1; + + while (i>flag-1){ + count+=array.get(i)*2; + i-=n; + } + + if(flag>0){ + count+=array.get(i)*2; + } + } +} diff --git a/boj/ashsty/week2/1890.java b/boj/ashsty/week2/1890.java new file mode 100644 index 0000000..7eef847 --- /dev/null +++ b/boj/ashsty/week2/1890.java @@ -0,0 +1,49 @@ +import java.util.*; +import java.io.*; + +public class Main{ + + static int max=0; + static int m; + static int n; + static int count = 0; + static int[][] map; + static long[][] check; + + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + m = Integer.parseInt(br.readLine()); + + map = new int[m+1][m+1]; + check = new long[m+1][m+1]; + + for(int i=1; i<=m; i++){ + StringTokenizer str = new StringTokenizer(br.readLine()); + for(int j=1; j<=m; j++){ + map[i][j] = Integer.parseInt(str.nextToken()); + } + } + + check[1][1]=1; + dp(1, 1); + + System.out.println(check[m][m]); + } + + private static void dp(int startX, int startY){ + int num=0; + + for(int i=startX; i<=m;i++){ + for(int j=startY; j<=m; j++){ + num = map[i][j]; + if(i+num<=m && num !=0){ + check[i+num][j] +=check[i][j]; + } + if(j+num<=m && num !=0){ + check[i][j+num] +=check[i][j]; + } + } + } + } +} diff --git a/boj/ashsty/week2/5567.java b/boj/ashsty/week2/5567.java new file mode 100644 index 0000000..076771b --- /dev/null +++ b/boj/ashsty/week2/5567.java @@ -0,0 +1,54 @@ +import java.util.*; +import java.io.*; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int n = Integer.parseInt(br.readLine()); // 총 동기의 수 + int m = Integer.parseInt(br.readLine()); // 친구 관계의 수 + + // 친구 관계를 저장할 인접 리스트 + List> friends = new ArrayList<>(); + for (int i = 0; i <= n; i++) { + friends.add(new ArrayList<>()); + } + + // 친구 관계 입력 받기 + for (int i = 0; i < m; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + friends.get(a).add(b); + friends.get(b).add(a); + } + + // BFS를 위한 변수 + boolean[] visited = new boolean[n + 1]; + Queue queue = new LinkedList<>(); + int count = 0; + int level = 0; + + // 상근이의 친구를 찾기 위한 BFS + visited[1] = true; + queue.add(1); + + while (!queue.isEmpty() && level < 2) { + int size = queue.size(); + for (int i = 0; i < size; i++) { + int current = queue.poll(); + for (int friend : friends.get(current)) { + if (!visited[friend]) { + visited[friend] = true; + queue.add(friend); + count++; + } + } + } + level++; + } + + System.out.println(count); + } +} diff --git a/boj/youngsu5582/week1/1260.java b/boj/youngsu5582/week1/1260.java deleted file mode 100644 index 600bdaa..0000000 --- a/boj/youngsu5582/week1/1260.java +++ /dev/null @@ -1,67 +0,0 @@ -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.StringTokenizer; - -public class Main { - private static final StringBuilder sb = new StringBuilder(); - - public static void main(final String[] args) throws IOException { - final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st = new StringTokenizer(reader.readLine(), " "); - - int n = Integer.parseInt(st.nextToken()); - int m = Integer.parseInt(st.nextToken()); - final int v = Integer.parseInt(st.nextToken()); - - - final int[][] ary = new int[n + 1][n + 1]; - final boolean[] visited = new boolean[n + 1]; - final boolean[] visited2 = visited.clone(); - for (int i = 0; i < m; i++) { - st = new StringTokenizer(reader.readLine(), " "); - final int x = Integer.parseInt(st.nextToken()); - final int y = Integer.parseInt(st.nextToken()); - ary[x][y] = 1; - ary[y][x] = 1; - } - dfs(visited, ary, v); - sb.append("\n"); - bfs(visited2, ary, v); - System.out.println(sb); - - } - - public static void dfs(boolean[] visited, int[][] ary, int pos) { - visited[pos] = true; - sb.append(pos) - .append(" "); - for (int i = 1; i < ary[pos].length; i++) { - if (!visited[i] && ary[pos][i] == 1) { - dfs(visited, ary, i); - } - } - } - - public static void bfs(boolean[] visited, int[][] ary, int pos) { - Deque temp = new ArrayDeque<>(); - temp.add(pos); - while (!temp.isEmpty()) { - pos = temp.pollFirst(); - if (visited[pos]) { - continue; - } - visited[pos] = true; - sb.append(pos) - .append(" "); - for (int i = 1; i < ary[pos].length; i++) { - if (!visited[i] && ary[pos][i] == 1) { - temp.add(i); - } - } - } - } - -} diff --git a/boj/youngsu5582/week1/2606.java b/boj/youngsu5582/week1/2606.java deleted file mode 100644 index 917ea48..0000000 --- a/boj/youngsu5582/week1/2606.java +++ /dev/null @@ -1,43 +0,0 @@ -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.StringTokenizer; - -public class Main { - private static boolean[] visited; - private static int[][] ary; - private static int n; - private static int count; - - public static void main(final String[] args) throws IOException { - final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - - n = Integer.valueOf(reader.readLine()); - int m = Integer.parseInt(reader.readLine()); - - ary = new int[n + 1][n + 1]; - - for (int i = 0; i < m; i++) { - StringTokenizer st = new StringTokenizer(reader.readLine(), " "); - int x = Integer.parseInt(st.nextToken()); - int y = Integer.parseInt(st.nextToken()); - ary[x][y] = 1; - ary[y][x] = 1; - } - - visited = new boolean[n + 1]; - dfs(1); - System.out.println(count-1); - } - - public static void dfs(int pos) { - visited[pos] = true; - count++; - for (int i = 1; i <= n; i++) { - if(!visited[i] && ary[pos][i]==1) { - dfs(i); - } - } - } - -} diff --git a/boj/youngsu5582/week1/2839.java b/boj/youngsu5582/week1/2839.java deleted file mode 100644 index ecaae23..0000000 --- a/boj/youngsu5582/week1/2839.java +++ /dev/null @@ -1,30 +0,0 @@ -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; - -public class Main { - private static final StringBuilder sb = new StringBuilder(); - - public static void main(final String[] args) throws IOException { - final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - final int n = Integer.parseInt(reader.readLine()); - - int result = Integer.MAX_VALUE; - - for(int i = 0; i*5 <=n; i++) { - for(int j = 0; i*5 + j*3 <=n; j++) { - if(i*5 + j*3 == n){ - result = Math.min(result,i+j); - } - } - } - - if(result==Integer.MAX_VALUE){ - sb.append(-1); - }else{ - sb.append(result); - } - - System.out.println(sb); - } -} diff --git a/programmers/youngsu5582/178871.java b/programmers/youngsu5582/178871.java deleted file mode 100644 index 94ad92c..0000000 --- a/programmers/youngsu5582/178871.java +++ /dev/null @@ -1,37 +0,0 @@ -import java.io.IOException; -import java.util.*; - -public class Main { - private static Map mp = new HashMap<>(); - - public static void main(final String[] args){ - String[] players = new String[]{"mumu", "soe", "poe", "kai", "mine"}; - String[] answers = new String[]{"kai", "kai", "mine", "mine"}; - Arrays.stream(solution(players,answers)).forEach(System.out::println); - } - - public static String[] solution(String[] players, String[] callings) { - init(players); - for (String calling : callings) { - int index = find(calling); - swap(players,calling,index); - } - return players; - } - private static void init(String[] players){ - for(int i = 0; i