Skip to content

Commit

Permalink
Merge pull request #283 from TearofCoding/main
Browse files Browse the repository at this point in the history
김기찬 / 10월 3주차 / 목
  • Loading branch information
TearofCoding authored Oct 23, 2023
2 parents 554815f + 9d8df2a commit 6fe39ab
Show file tree
Hide file tree
Showing 7 changed files with 320 additions and 0 deletions.
46 changes: 46 additions & 0 deletions KimKiChan/boj/A와B2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package boj;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Objects;

//12919번
public class A와B2 {
static boolean able = false;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String s = br.readLine();
String t = br.readLine();

sol(s, t);

if(able) System.out.println(1);
else System.out.println(0);
}

private static void sol(String s, String t) {
if(able) return;
if(s.length() == t.length()) {
// System.out.println(s);
if(Objects.equals(s, t)) {
able = true;
}
return;
}

if(t.charAt(t.length()-1) == 'A') {
sol(s, t.substring(0, t.length()-1));
}

if(t.charAt(0) == 'B') {
String substr = t.substring(1);
StringBuilder sb = new StringBuilder(substr);
sb.reverse();
sol(s, sb.toString());
}


}

}
54 changes: 54 additions & 0 deletions KimKiChan/boj/MessiGimossi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package boj;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class MessiGimossi {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int m = Integer.parseInt(br.readLine());

ArrayList<Integer> Messi = new ArrayList<>(); // Messi의 길이
Messi.add(6); // "Messi "
Messi.add(14);// "Gimossi "
String str = " Messi Gimossi ";
if(m <= 14) {
if(str.charAt(m) == ' ') {
System.out.println("Messi Messi Gimossi");
}else {
System.out.println(str.charAt(m));
}
}else {
while(true) {
if(Messi.get(Messi.size()-1) > m) break;

Messi.add(Messi.get(Messi.size()-1) + Messi.get(Messi.size()-2));
}
m -= Messi.get(Messi.size()-2);
int index = Messi.size()-3;
// m은 Messi[index] 어딘가에 있다

//Messi Gimmossi까지 뺀다
while(index >= 2) {
if(m < 14) break;

if(m <= Messi.get(index) && m > Messi.get(index-1)) {
m -= Messi.get(index-1);
index-=2;
}else if(m <= Messi.get(index-1)) {
index-=1;
}
}


if(str.charAt(m) == ' ') {
System.out.println("Messi Messi Gimossi");
}else {
System.out.println(str.charAt(m));
}

}

}
}
31 changes: 31 additions & 0 deletions KimKiChan/boj/더하기.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package boj;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

//15989번
public class 더하기 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int[] sum = new int[10001]; // 만드는 경우의 수
Arrays.fill(sum, 1);

for(int i = 2; i <= 10000; i++) {
sum[i] += sum[i-2];
}
for(int i = 3; i <= 10000; i++) {
sum[i] += sum[i-3];
}

int t = Integer.parseInt(br.readLine());
for(int i = 0; i < t; i++) {
int n = Integer.parseInt(br.readLine());

sb.append(sum[n]).append("\n");
}
System.out.println(sb);

}
}
2 changes: 2 additions & 0 deletions KimKiChan/boj/두동전.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package boj;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
Expand Down
87 changes: 87 additions & 0 deletions KimKiChan/boj/무기공학.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package boj;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class 무기공학 {
private static int[][] dxdy = {{1,0},{0,-1},{-1,0},{0,1}};//아래 왼쪽 위 오른쪽
private static int n;
private static int m;
private static boolean[][] used;
private static int[][] tree;
private static int maxScore;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

StringTokenizer st = new StringTokenizer(br.readLine(), " ");
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());

tree = new int[n][m];
for(int i = 0; i < n; i++) {
st = new StringTokenizer(br.readLine(), " ");
for(int j = 0; j < m; j++) {
tree[i][j] = Integer.parseInt(st.nextToken());
}
}

used = new boolean[n][m];
maxScore = 0;

sol(0, 0, 0);

System.out.println(maxScore);

}

private static void sol(int x, int y, int score) {
if(x==n) {
//최대값 찾기
if(maxScore < score) {
maxScore = score;
}
return;
}

if(!used[x][y]) {
//4가지 부메랑 -> 다음 좌표 -> 전부 시도하면 빈칸으로
for(int dir = 0; dir < 4; dir++) {
int dir2 = (dir+1)%4;
int nx1 = x + dxdy[dir][0];
int ny1 = y + dxdy[dir][1];
int nx2 = x + dxdy[dir2][0];
int ny2 = y + dxdy[dir2][1];
if(inRange(nx1, ny1) && inRange(nx2, ny2)) {
if(!used[nx1][ny1] && !used[nx2][ny2]) {
used[x][y] = true;
used[nx1][ny1] = true;
used[nx2][ny2] = true;

if(y+1<m) {
sol(x, y+1, score + tree[x][y]*2 + tree[nx1][ny1] + tree[nx2][ny2]);
}else {
sol(x+1, 0, score + tree[x][y]*2 + tree[nx1][ny1] + tree[nx2][ny2]);
}

used[nx2][ny2] = false;
used[nx1][ny1] = false;
used[x][y] = false;

}
}
}
}
//다음좌표로
if(y+1<m) {
sol(x, y+1, score);
}else {
sol(x+1, 0, score);
}

}

private static boolean inRange(int x, int y) {
return x>=0 && y>=0 && x<n && y<m;
}
}
43 changes: 43 additions & 0 deletions KimKiChan/boj/저울.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package boj;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

//10159번
public class 저울 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int m = Integer.parseInt(br.readLine());

int[][] dist = new int[n+1][n+1];

for(int i = 0; i < m; i++) {
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int from = Integer.parseInt(st.nextToken());
int to = Integer.parseInt(st.nextToken());
dist[from][to] = 1;
}

for(int k = 1; k <= n; k++) {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(dist[i][k]==1 && dist[k][j]==1) {
dist[i][j] = 1;
}
}
}
}
StringBuilder sb = new StringBuilder();
for(int i = 1; i <= n; i++) {
int count = 0;
for(int j = 1; j <= n; j++) {
if(i==j) continue;
if(dist[i][j] == 0 && dist[j][i] == 0) count++;
}
sb.append(count).append("\n");
}
System.out.println(sb);
}
}
57 changes: 57 additions & 0 deletions KimKiChan/boj/좋은수열.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package boj;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class 좋은수열 {
private static int[] arr;
private static int n;
private static boolean solved;

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());

arr = new int[n+1]; // 수열
solved = false;
sol(1);
}

private static void sol(int index) {
if(solved) return;
if(index == n+1) {
solved = true;
StringBuilder sb = new StringBuilder();
for(int i = 1; i < arr.length; i++) {
sb.append(arr[i]);
}
System.out.println(sb);
return;
}
for(int i = 1; i <= 3; i++) {
arr[index] = i;
//부분수열 체크 true
if(check(index)) {
sol(index+1);
}
}
}

private static boolean check(int index) { // 부분 수열 체크
int[] left;
int[] right;

for(int i = 1; i <= index/2; i++) {
left = new int[i];
right = new int[i];
for(int j = 0; j < i; j++) {
left[j] = arr[index-j-i];
right[j] = arr[index-j];
}
if(Arrays.equals(left, right)) return false;
}

return true;
}
}

0 comments on commit 6fe39ab

Please sign in to comment.