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

29_pushedrumex #143

Open
wants to merge 4 commits 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
38 changes: 38 additions & 0 deletions week-29/pushedrumex/DSLR.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from collections import deque, defaultdict
import sys
intput = sys.stdin.readline

T = int(input())
for _ in range(T):
A, B = map(int, input().split())

visited = defaultdict(bool)
q = deque([(A, "")])
while q:
now, cmd = q.popleft()
if now == B:
print(cmd)
break

D = now * 2 % 10000
S = 9999 if now == 0 else now - 1

s = ("0000" + str(now))[-4:]
L = int(s[1:] + s[0])
R = int(s[-1] + s[:-1])

if not visited[D]:
visited[D] = True
q.append((D, cmd + "D"))

if not visited[S]:
visited[S] = True
q.append((S, cmd + "S"))

if not visited[L]:
visited[L] = True
q.append((L, cmd + "L"))

if not visited[R]:
visited[R] = True
q.append((R, cmd + "R"))
96 changes: 96 additions & 0 deletions week-29/pushedrumex/낚시왕.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import java.io.*;

public class Main {
static int R, C, M;

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

R = Integer.parseInt(input[0]);
C = Integer.parseInt(input[1]);
M = Integer.parseInt(input[2]);

Shark[][] sharks = new Shark[R][C];

int r, c, s, d, z;
for (int i = 0; i < M; i++) {
input = br.readLine().split(" ");
r = Integer.parseInt(input[0]);
c = Integer.parseInt(input[1]);
s = Integer.parseInt(input[2]);
d = Integer.parseInt(input[3]);
z = Integer.parseInt(input[4]);
sharks[r-1][c-1] = new Shark(s, d, z);
}

int answer = 0;
for (int j = 0; j < C; j++) {
// 상어 잡기
for (int i = 0; i < R; i++) {
if (sharks[i][j] != null) {
answer += sharks[i][j].z;
sharks[i][j] = null;
break;
}
}
sharks = move(sharks);
}

System.out.println(answer);
}

static Shark[][] move(Shark[][] sharks) {
Shark[][] updatedSharks = new Shark[R][C];
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
if (sharks[i][j] != null) {
Shark shark = sharks[i][j];

int _i = i;
int _j = j;
int s;

if (shark.d == 1 || shark.d == 2) {
s = shark.s % (2 * (R - 1));
while (s-- > 0) {
if (_i == 0 && shark.d == 1) shark.d = 2;
else if (_i == R - 1 && shark.d == 2) shark.d = 1;

if (shark.d == 1) _i--;
else _i++;
}

} else {
s = shark.s % (2 * (C - 1));
while (s-- > 0) {
if (_j == 0 && shark.d == 4) shark.d = 3;
else if (_j == C - 1 && shark.d == 3) shark.d = 4;

if (shark.d == 3) _j++;
else _j--;
}

}

if (updatedSharks[_i][_j] != null && updatedSharks[_i][_j].z > shark.z) {
continue;
}
updatedSharks[_i][_j] = shark;
}
}
}
return updatedSharks;
}

static class Shark {
int s, d, z; // 속력, 방향, 크기

Shark(int s, int d, int z) {
this.s = s;
this.d = d;
this.z = z;
}
}

}
24 changes: 24 additions & 0 deletions week-29/pushedrumex/멀티버스.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
M, N = map(int, input().split())

universe = []
for _ in range(M):
universe.append(list(map(int, input().split())))

def is_balance(A, B):
for j in range(N-1):
for k in range(j+1, N):
if not ((A[j] < A[k] and B[j] < B[k]) or (A[j] == A[k] and B[j] == B[k]) or (A[j] > A[k] and B[j] > B[k])):
return False

return True

answer = 0
for i in range(M-1):
A = universe[i]
for j in range(i+1, M):
B = universe[j]
if is_balance(A, B):
answer += 1


print(answer)
48 changes: 48 additions & 0 deletions week-29/pushedrumex/홀수홀릭호석.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.io.*;

public class Main {
static int minValue = Integer.MAX_VALUE;
static int maxValue = 0;

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
dfs(N, 0);
System.out.println(minValue + " " + maxValue);
}

static int countOdd(int N) {
int odd = 0;
String[] str = String.valueOf(N).split("");
for (String n: str) {
if (Integer.parseInt(n) % 2 != 0) {
odd++;
}
}
return odd;
}

static void dfs(int N, int odd) {
odd += countOdd(N);
int length = String.valueOf(N).length();

if (length == 1) {
minValue = Math.min(minValue, odd);
maxValue = Math.max(maxValue, odd);
} else if (length == 2) {
dfs(N / 10 + N % 10, odd);
} else {
String str = String.valueOf(N);
for (int i = 1; i < length - 1; i++) {
for (int j = i + 1; j < length; j++) {
int next = Integer.parseInt(str.substring(0, i)) +
Integer.parseInt(str.substring(i, j)) +
Integer.parseInt(str.substring(j, length));

dfs(next, odd);
}
}
}
}

}