Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions Basic_Of_Algorithm/src/Today_22_06_02/arrow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package Today_22_06_02;

import java.util.ArrayList;
import java.util.Collections;

public class arrow {

static int apeach[];
static int ryan[];
static int count;
static int maxvalue = 0;
static ArrayList<int[]> answerList = new ArrayList<>();

public static void main(String[] args) {

int[]info = {0,0,1,2,0,1,1,1,1,1,1};
int n = 9;

apeach = info.clone();
count = n;
ryan = new int[info.length];

dfs(0,0);

int [] answer;

if(answerList.isEmpty()) answer = new int[] {-1};

else {

Collections.sort(answerList,(o1,o2)->{

for(int i=10;i>-1;i--) {
if(o1[i]!=o2[i]) return o2[i] - o1[i];
}

return 0;

});

answer = new int[apeach.length];

for(int i=0;i<apeach.length;i++) answer[i] = answerList.get(0)[i];


for(int i : answer)System.out.print(i+", ");
}





}
static void dfs(int start, int arrow) {

if(arrow==count) {

int r = 0;
int a = 0;

for(int i=0;i<11;i++) {
if(ryan[i]==0 && apeach[i]==0) continue;

if(ryan[i]>apeach[i]) r += 10 - i;
else a += 10 - i;
}

if(r>a) {
int diff = r - a;
if(diff>maxvalue) {
maxvalue = diff;
answerList.clear();
answerList.add(ryan.clone());

}else if(diff==maxvalue) {
answerList.add(ryan.clone());
}
}

return;
}


for(int i=0;i<11;i++) {
ryan[i]++;
dfs(i,arrow+1);
ryan[i]--;
}

}
}
90 changes: 90 additions & 0 deletions Basic_Of_Algorithm/src/Today_22_06_02/coronaTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package Today_22_06_02;

public class coronaTest {

public static void main(String[] args) {

String[][]places = {{"POOOP", "OXXOX", "OPXPX", "OOXOX", "POXXP"}, {"POOPX", "OXPXP", "PXXXO", "OXXXO", "OOOPP"}, {"PXOPX", "OXOXP", "OXPOX", "OXXOP", "PXPOX"}, {"OOOXX", "XOOOX", "OOOXX", "OXOOX", "OOOOO"}, {"PXPXP", "XPXPX", "PXPXP", "XPXPX", "PXPXP"}};
int []result = new int[places.length];

for(int i=0;i<places.length;i++) {

char[][]map = new char[places[0].length][places[0][0].length()];

for(int j=0;j<places[i].length;j++) {
for(int k=0;k<places[j].length;k++) {
map[j][k] = places[i][j].charAt(k);
}
}

result[i] = check(map);
}

for(int i : result)System.out.println(i);


}

static boolean isRight(char[][]map,int i,int j) {

//상하좌우
int [][] move1 = {{-1,0},{1,0},{-1,0},{0,1}};

for(int d=0;d<4;d++) {
int newI = i + move1[d][0];
int newJ = j + move1[d][1];

if(newI<0||newJ<0||map.length-1<newI||map[0].length-1<newJ) continue;

if(map[newI][newJ]=='P') return false;

}
//대각선
int [][] move2 = {{1,1},{-1,1},{1,-1},{-1,-1}};

for(int d=0;d<4;d++) {
int newI = i + move2[d][0];
int newJ = j + move2[d][1];

if(newI<0||newJ<0||map.length-1<newI||map[0].length-1<newJ) continue;

if(map[newI][newJ]=='P') {
if(!(map[newI][j]=='X' && map[i][newJ]=='X')) return false;
}
}
//맨해튼
int [][] move3 = {{-2,0},{2,0},{0,-2},{0,2}};

for(int d=0;d<4;d++) {
int newI = i + move3[d][0];
int newJ = j + move3[d][1];

if(newI<0||newJ<0||map.length-1<newI||map[0].length-1<newJ) continue;
if(map[newI][newJ]=='P') {
if(map[(newI+i)/2][(newJ+j)/2]!='X') return false;
}
}

return true;
}

static int check(char[][]map) {

for(int i=0;i<map.length;i++) {
for(int j=0;j<map[0].length;j++) {
if(map[i][j]=='P') {
if(!isRight(map,i,j)) {
return 0;
}
}
}
}



return 1;


}

}
80 changes: 80 additions & 0 deletions Basic_Of_Algorithm/src/Today_22_06_02/delivery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package Today_22_06_02;

import java.util.Queue;
import java.util.LinkedList;

public class delivery {

public static void main(String[] args) {


int INF = 50001;
int n = 4;

int[][]road = {{1,2,1},{1,3,5},{2,3,1},{2,4,2}};
int k = 2;
int answer = 0;

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

for(int i = 1 ; i <=n; i++) {
for(int j=1; j<=n ; j++) {
if(i==j) continue;
map[i][j] = INF; //무한대
}
}


for(int i=0;i<road.length;i++) {
int a = road[i][0];
int b = road[i][1];
int w = road[i][2];
//무한대 보다 작으면 간선의 정보 저장
if(map[a][b] > w) {
map[a][b] = w;
map[b][a] = w;
}

}

int [] dist = new int[n+1];
for(int i = 2; i <= n ; i++) {
dist[i] = INF;
}

boolean[] visited = new boolean[n+1];
visited[1] = true;


for(int i=1; i <=n-1 ; i++) {

int min_idx = 1;
int min_value = INF;
for(int j=2;j<=n;j++) {
if(!visited[j] && dist[j]<min_value) {
min_value = dist[j];
min_idx = j;
}
}

visited[min_idx] = true;


for(int j = 2; j <= n ; j++) {
if(dist[j]>dist[min_idx] + map[min_idx][j]) {
dist[j] = dist[min_idx] + map[min_idx][j];
}
}

}

for(int i=1;i<=n;i++) {
if(dist[i]<=k) answer++;
}

for(int i : dist)System.out.print(i+",");
System.out.println();
System.out.println(answer);
}

}
34 changes: 34 additions & 0 deletions Basic_Of_Algorithm/src/Today_22_06_02/hanoi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package Today_22_06_02;

public class hanoi {

public static void main(String[] args) {

int n = 4;

int [] arr = {1,2,3};

hanoi(arr[0],arr[1],arr[2],n);


//n개를 옮기는 문제는 n-1로 세분화되고 다시 n-1를 위해 1를 옮기는걸 세분화 시킨다
// a -> b (n-1)개 옮기기
// b - > c (n-1)개 옮기기
//n ==1 마지막에 남은거 옮기기

}

static void hanoi(int from, int by, int to,int n) {

if(n==1) {
System.out.println(from + " - > " + to);
return;
}

hanoi(from, to, by, n-1);
System.out.println(from + " - > " + to);
hanoi(by,from,to,n-1);

}

}
57 changes: 57 additions & 0 deletions Basic_Of_Algorithm/src/Today_22_06_02/openChatting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package Today_22_06_02;

import java.util.ArrayList;
import java.util.HashMap;

public class openChatting {



public static void main(String[] args) {

String [] record = {"Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"};
ArrayList<String> answerList = new ArrayList<>();

HashMap<String,String>idMap = new HashMap<>();

for(String str : record) {

String []temp = str.split(" ");

String action = temp[0];
String id = temp[1];

if(action.equals("Leave")) continue;

String nick = temp[2];

idMap.put(id, nick);


}

for(String str : record) {

String []temp = str.split(" ");

String action = temp[0];
if(action.equals("Change")) continue;
String id = temp[1];
String nick = idMap.get(id);

String ans = nick+"님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다.");

answerList.add(ans);

}

String[]answer = new String[answerList.size()];

for(int i=0;i<answer.length;i++) answer[i] = answerList.get(i);

for(String str : answer)System.out.println(str);



}
}
Loading