Skip to content

Commit

Permalink
Merge pull request #276 from nahokyun/main
Browse files Browse the repository at this point in the history
나호균 / 10월 3주차 / 월
  • Loading branch information
nahokyun authored Oct 19, 2023
2 parents 30c283c + 54789d8 commit ac23d93
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 0 deletions.
113 changes: 113 additions & 0 deletions Nahokyun/boj/boj16197.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package boj;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.awt.Point;

public class boj16197 {

private static char[][] map;
private static int[] dx = { 0, 0, 1, -1 };
private static int[] dy = { 1, -1, 0, 0 };
private static int n;
private static int m;

static int minMove=401;

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());

map = new char[n][m];
boolean isSecond = false;
Point first = null;
Point second = null;
for (int i = 0; i < n; i++) {
String s = br.readLine();
for (int j = 0; j < m; j++) {
map[i][j] = s.charAt(j);
if (map[i][j] == 'o') {
if (!isSecond) {
first = new Point(j, i);
isSecond = true;
} else {
second = new Point(j, i);
}
}
}
}
// 입력 종료


track(first, second, 0);
System.out.println(minMove==401?-1:minMove);

}

private static void track(Point first, Point second, int moveCount) {
if(moveCount>=10||(first.x==second.x&&first.y==second.y)) {

return;
}
int f_curX=first.x;
int f_curY=first.y;
int s_curX=second.x;
int s_curY=second.y;

for(int i=0;i<4;i++) {
int f_cmpX=first.x+dx[i];
int f_cmpY=first.y+dy[i];
int s_cmpX=second.x+dx[i];
int s_cmpY=second.y+dy[i];

if(f_cmpX>=0&&f_cmpY>=0&&f_cmpY<n&&f_cmpX<m
&&s_cmpX>=0&&s_cmpY>=0&&s_cmpY<n&&s_cmpX<m) {
//둘다 범위에 있을때
if(map[f_cmpY][f_cmpX]=='#'&&map[s_cmpY][s_cmpX]!='#') {
second.x=s_cmpX;
second.y=s_cmpY;
track(first,second,moveCount+1);
second.x=s_curX;
second.y=s_curY;
}else if(map[f_cmpY][f_cmpX]!='#'&&map[s_cmpY][s_cmpX]=='#') {
first.x=f_cmpX;
first.y=f_cmpY;
track(first,second,moveCount+1);
first.x=f_curX;
first.y=f_curY;
}else if(map[f_cmpY][f_cmpX]=='#'&&map[s_cmpY][s_cmpX]=='#') {
continue;
}else {
first.x=f_cmpX;
first.y=f_cmpY;
second.x=s_cmpX;
second.y=s_cmpY;
track(first,second,moveCount+1);
second.x=s_curX;
second.y=s_curY;
first.x=f_curX;
first.y=f_curY;
}
}else if(f_cmpX>=0&&f_cmpY>=0&&f_cmpY<n&&f_cmpX<m
&&(s_cmpX<0||s_cmpX>=m||s_cmpY<0||s_cmpY>=n)) {
minMove=Math.min(minMove, moveCount+1);
}else if(s_cmpX>=0&&s_cmpY>=0&&s_cmpY<n&&s_cmpX<m
&&(f_cmpX<0||f_cmpX>=m||f_cmpY<0||f_cmpY>=n)) {
minMove=Math.min(minMove, moveCount+1);
}


}





}

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class boj17951 {

private static int k;
private static int n;
private static int[] score;

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

st=new StringTokenizer(br.readLine());
score = new int[n];
int right=0;
int left=0;

for(int i=0;i<n;i++) {
score[i]=Integer.parseInt(st.nextToken());
right+=score[i];
}

int mid=0;

while(left<=right) {
mid=(left+right)>>1;

if(check(mid)) {
left=mid+1;
}else {
right=mid-1;
}
}

System.out.println(right);

}

private static boolean check(int mid) {
int sum=0;
ArrayList<Integer> tmp=new ArrayList<>();
for(int i=0;i<n;i++) {
sum+=score[i];
if(sum>=mid) {
tmp.add(sum);
sum=0;
}
}
if(tmp.size()>=k) {//그룹이 많을때 -> 합을 늘려야함
return true;
}


return false;
}

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class boj3066 {

public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int t = Integer.parseInt(br.readLine());

for (int test = 1; test <= t; test++) {
int n = Integer.parseInt(br.readLine());
int[] arr = new int[n];
int[] dp = new int[n+1];

for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(br.readLine());
}


int idx=1;
dp[0]=arr[0];
for(int i=1;i<n;i++) {
int cur=arr[i];

if(dp[idx-1]<arr[i]) {
dp[idx++]=arr[i];
}else {
int left=0;
int right=idx;
while(left<=right) {
int mid=(left+right)>>1;
if(dp[mid]>cur) {
right=mid-1;
}else {
left=mid+1;
}
}
dp[left]=cur;
}
}

System.out.println(idx);
}
}

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

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

public class boj4811 {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
int[] arr=new int[1001];
int max=0;
int idx=1;

while(true) {
int n = Integer.parseInt(br.readLine());
if(n==0) {
break;
}
arr[idx++]=n;
max=Math.max(max, n);
}

long[] dp=new long[max+1];
dp[0]=1;
for(int i=1;i<=max;i++) {
for(int j=0;j<i;j++) {
dp[i]+=dp[j]*dp[i-j-1];
}
}

for(int i=1;i<idx;i++) {
sb.append(dp[arr[i]]).append('\n');
}

System.out.println(sb);

}


}

0 comments on commit ac23d93

Please sign in to comment.