Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[minzino]0224 외벽점검 실패 #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.org.example.feb.bj20310;
package main.java.org.example.feb.backjoon.bj20310;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package main.java.org.example.feb.programmers.외벽_점검;

public class Solution {
int[] weak, dist;
int[][] weak_cases;
int n, answer;

public int solution(int n, int[] weak, int[] dist) {
weak_cases = new int[weak.length][weak.length];
this.weak = weak;
this.dist = dist;
this.answer = dist.length+1;
this.n = n;


makeWeakCases();
makeDistCases(new boolean[dist.length], new int[dist.length], 0);
if(answer == dist.length+1)
return -1;
else
return answer;
}

void makeWeakCases(){
int[] weak_case = this.weak.clone();
weak_cases[0] = weak_case.clone();
for(int i = 1; i < weak.length; i++){
int temp = weak_case[0];
for(int j = 1; j < weak.length; j++){
weak_case[j-1] = weak_case[j];
}
weak_case[weak.length-1] = temp+n;
weak_cases[i] = weak_case.clone();
}
}

void makeDistCases(boolean[] dist_visit, int[] dist_case, int idx){
if(idx == dist.length){
for(int[] weak_case: weak_cases)
check(dist_case, weak_case);
}
for(int i = 0; i < dist.length; i++){
if(!dist_visit[i]){
dist_visit[i] = true;
dist_case[idx] = dist[i];
makeDistCases(dist_visit, dist_case, idx+1);
dist_case[idx] = 0;
dist_visit[i] = false;
}
}
}

void check(int[] dist_case, int[] weak_case){
int cur = 0, next;
int dist_idx = 0;
while(cur < weak_case.length && dist_idx < dist_case.length){
next = cur+1;
while(next < weak_case.length &&
weak_case[cur] + dist_case[dist_idx] >= weak_case[next]){
next++;
}
cur = next;
dist_idx++;
}

if(cur == weak_case.length && dist_idx < answer)
answer = dist_idx;
}
}