Skip to content

[3주차] 이지영 #32

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

Merged
merged 9 commits into from
Sep 29, 2024
Merged

[3주차] 이지영 #32

merged 9 commits into from
Sep 29, 2024

Conversation

yeongleej
Copy link
Contributor

No description provided.

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int[] dp = new int[10001];
// 1로 초기화 : 1만 써서 만들기
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헉.. 1부터 하나씩 초기화해나가니까 코드가 깔끔하군요....!👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생각하는데 굉장한 시간이 걸렸습니다,,,, 어려워요 dp ^^ㅠㅠㅠ

static int ans;
static int MAX = Integer.MAX_VALUE;
static int[][] g;
static int[] nrr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 int[] nrr이 어떤 정보를 저장하는 변수인지 알 수 있을까요?,,!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

각 사다리에 연결된 유실선의 수를 나타내려고 선언했습니다. 여러 방법을 시도해보다가 각 사다리에 연결된 유실선의 개수가 짝수면 가능하다는 가설을 세우고 코드를 작성했는데,,,!! 통과가 되더라고요,,,, 그런데 다른 분들의 코드를 참고하고 다시 고려해보니깐 제 코드는 엣지케이스를 고려하지 못하는 잘못된 코드인 것 같습니다!!! ㅎㅎㅎ

다른 분들의 코드를 참고해서 다시 풀어보겠습니다.!!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아! 백준에 똑같은 문제(사다리 조작)가 있는데, 여기에 케이스가 많아서 이거 되는지 확인해보면 좋을 것 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오오 감사합니다! 👍

// 다리 길이 만큼 임시로 크기가 0인 트럭 올리기
for(int w=0; w<W; w++) {
bridges.add(0);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호,,, 처음 다리에 다리 길이만큼 큐를 채워주고 시간이 지날 때마다 다리 큐에서 하나씩 빼주는 거군요,,,,,

좋은 방법인 것 같습니다 !!!!!👍

for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) {
if(s[i][j]) {
int nx = (i + dx[dir]*cnt + N) % N;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

따로 음수일경우 if처리 안하고, 애초에 +N하면 더 간결하고 깔끔해지는군요..!

Copy link
Contributor

@KodaHye KodaHye Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

근데 이 때, N이 3이고, 방향이 ↑ ↖ ← ↙중 하나고, p(cnt)의 값이 6이 넘어가게 되면 좌표가 음수가 될 수도 있어서 cnt 값을 N으로 나눠줘야된다고 생각하는데, 아닌가요?,,,

Copy link
Contributor Author

@yeongleej yeongleej Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞아요!! 그런데 문제에 1 ≤ p ≤ min(n, 10)이라는 조건이 있어서 p의 값이 n을 넘는 경우는 생각하지 않았습니다!

(만약 이 조건이 없다면, 다혜님이 말한대로 음수가 되기 때문에 cnt를 먼저 모듈러 연산한 후에 계산해야 할 것 같습니다. 👍 )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하!! p <= min(n, 10)이라는 조건이 있었군요,,,,
조건을 봤는데도 문제에 대해 정확하게 이해하지 않았었네요,, !!! 답변 감사합니다!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음수 처리를 안해줘서 헤매고 있었는데 아이디어 감사합니다!!

System.out.println(Arrays.toString(arr[i]));
}
}
public static void moveVita(int dir, int cnt) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅋㅎㅋㅎ비타 함수명 재밌네요😁

}
public static boolean isOk() {
for(int i=1; i<N+1; i++){
if(nrr[i] % 2 != 0) return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 배워갑니다🤓
자신으로 돌아오려면 자신에게서 연결된 사다리의 수가 반드시 짝수여야 하는데
움직임을 구현하기 전에 이 처리를 먼저 해줘서 해당 조합을 움직여 볼건지, 아닌지를 미리 판단할 수 있어서 좀 더 효율적으로 짤 수 있었을 것 같아요!👍🏻

@yeongleej yeongleej merged commit 0350942 into GreatAlgorithm-Study:main Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants