-
Notifications
You must be signed in to change notification settings - Fork 4
[10주차] 고다혜 #141
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
[10주차] 고다혜 #141
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
23e49e9
고다혜: [CT] 회전하는 빙하_241111
KodaHye c668aa9
고다혜: [SQL] 언어별 개발자 분류하기_241112
KodaHye 87ae121
고다혜: [BOJ] 2955 스도쿠 풀기_241112
KodaHye d729f7b
고다혜: [BOJ] 1613 역사_241113
KodaHye 9918da3
고다혜: [BOJ] 2096 내려가기_241113
KodaHye ffce1db
고다혜: [PG] 42884 단속 카메라_241115
KodaHye bba50cd
고다혜: [PG] 181188 요격 시스템_241115
KodaHye 6d3b20d
고다혜: [PG] 150366 표 병합_241114
KodaHye 4f95646
고다혜: [PG] 150366 표 병합_241114
KodaHye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
BOJ/1000-5000번/DH_1613.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
/* | ||
* 역사 | ||
*/ | ||
|
||
public class DH_1613 { | ||
static final int INF = Integer.MAX_VALUE; | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static StringTokenizer st; | ||
static int[][] arr; | ||
|
||
public static void main(String[] args) throws Exception { | ||
initInput(); | ||
solution(); | ||
getOrder(); | ||
} | ||
|
||
static void getOrder() throws Exception { | ||
int n = Integer.parseInt(br.readLine()); | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
|
||
for(int i = 0; i < n; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int s = Integer.parseInt(st.nextToken()); | ||
int e = Integer.parseInt(st.nextToken()); | ||
|
||
// s지점에서 e지점으로 가거나, e지점에서 s지점으로 가는 길이 둘 다 없는 경우는 선후 관계를 알 수 없음 | ||
if(arr[s][e] == INF && arr[e][s] == INF) sb.append(0); | ||
else if(arr[s][e] != Integer.MAX_VALUE) sb.append(-1); // s에서 e지점으로 갈 수 있다면 s가 더 빠른 사건 | ||
else sb.append(1); // 반대의 경우라면 e가 더 빠른 사건 | ||
sb.append("\n"); | ||
} | ||
|
||
System.out.println(sb); | ||
} | ||
|
||
// 플로이도워셜을 통해 각 지점간 거리 구하기 | ||
static void solution() { | ||
for(int k = 1; k < arr.length; k++) { | ||
for(int s = 1; s < arr.length; s++) { | ||
if(s == k || arr[s][k] == INF) continue; | ||
for(int e = 1; e < arr.length; e++) { | ||
if(e == k || e == s || arr[k][e] == INF) continue; | ||
|
||
if(arr[s][e] > arr[s][k] + arr[k][e]) | ||
arr[s][e] = arr[s][k] + arr[k][e]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
static void initInput() throws Exception { | ||
st = new StringTokenizer(br.readLine()); | ||
|
||
int n = Integer.parseInt(st.nextToken()); | ||
int k = Integer.parseInt(st.nextToken()); | ||
|
||
arr = new int[n + 1][n + 1]; | ||
|
||
// 초기 지점 간 거리 무한대로 초기화해주기 | ||
for(int r = 0; r < arr.length; r++) Arrays.fill(arr[r], INF); | ||
|
||
for(int i = 0; i < k; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
|
||
int s = Integer.parseInt(st.nextToken()); | ||
int e = Integer.parseInt(st.nextToken()); | ||
|
||
arr[s][e] = 1; | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
BOJ/1000-5000번/DH_2096.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
/* | ||
* 내려가기 | ||
*/ | ||
|
||
public class DH_2096 { | ||
static int[][] map, max, min; | ||
|
||
public static void main(String[] args) throws Exception { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
|
||
int N = Integer.parseInt(br.readLine()); | ||
map = new int[N + 1][3]; | ||
max = new int[N + 1][3]; // 각 줄마다 최댓값을 저장할 변수 | ||
min = new int[N + 1][3]; // 각 줄마다 최솟값을 저장할 변수 | ||
|
||
// 최솟값을 저장하는 변수는 무한으로 초기화 | ||
for(int r = 1; r < min.length; r++) Arrays.fill(min[r], Integer.MAX_VALUE >> 2); | ||
for(int r = 1; r < map.length; r++) { | ||
st= new StringTokenizer(br.readLine()); | ||
for(int c = 0; c < 3; c++) map[r][c] = Integer.parseInt(st.nextToken()); | ||
|
||
for(int pc = 0; pc < 3; pc++) { | ||
for(int dc = -1; dc < 2; dc++) { | ||
int nc = pc + dc; | ||
if(nc < 0 || nc >= 3) continue; | ||
|
||
max[r][nc] = Math.max(max[r - 1][pc] + map[r][nc], max[r][nc]); | ||
min[r][nc] = Math.min(min[r - 1][pc] + map[r][nc], min[r][nc]); | ||
} | ||
} | ||
} | ||
|
||
int maxValue = Integer.MIN_VALUE, minValue = Integer.MAX_VALUE; | ||
for(int c = 0; c < 3; c++) { | ||
maxValue = Math.max(maxValue, max[N][c]); | ||
minValue = Math.min(minValue, min[N][c]); | ||
} | ||
|
||
System.out.println(maxValue + " " + minValue); | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
BOJ/1000-5000번/DH_2955.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
/* | ||
* 스도쿠 풀기 | ||
*/ | ||
|
||
public class DH_2955 { | ||
static boolean error; // 스도쿠에 모순이 일어나는지 확인하는 변수 | ||
static char[][] map; | ||
static boolean[][][] v; // 1부터 9까지 위치할 수 있는 곳을 표시하는 변수 | ||
static HashSet<Integer>[] set; // 스코쿠 판을 3 X 3으로 나누었을 때, 1 ~ 9번째 칸에서 어떤 수가 있는지 저장하는 변수 | ||
|
||
public static void main(String[] args) throws Exception { | ||
initInput(); | ||
System.out.println(solution() ? printMap(): "ERROR"); | ||
} | ||
|
||
static boolean solution() { | ||
if(error) return false; | ||
L: while(true) { | ||
int putCnt = 0; | ||
|
||
// 1부터 9까지 차례로 입력 | ||
for(int k = 1; k < 10; k++) { | ||
// map에서 3 X 3크기의 배열씩 확인함 | ||
for(int r = 0; r < 7; r += 3) { | ||
for(int c = 0; c < 7; c += 3) { | ||
// 3 X 3 배열에 k가 있으면 continue; | ||
int idx = (r / 3) * 3 + c / 3; | ||
if(set[idx].contains(k)) continue; | ||
|
||
// 3 X 3 배열에 k가 없으면 있을 수 있는 지점 개수 세기 | ||
int canExistPoint = 0; // 있을 수 있는 지점 개수 | ||
int pr = 0, pc = 0; | ||
for(int sr = r; sr < r + 3; sr++) { | ||
for(int sc = c; sc < c + 3; sc++) { | ||
if(!v[k][sr][sc] && map[sr][sc] == '.') { | ||
canExistPoint += 1; | ||
pr = sr; | ||
pc = sc; | ||
} | ||
} | ||
} | ||
|
||
// 있을 수 있는 곳이 없으면 잘못된 스도쿠 | ||
if(canExistPoint == 0) { | ||
error = true; | ||
break L; | ||
} | ||
|
||
// 있을 수 있는 곳이 한 곳이라면 | ||
// 숫자 입력하기 | ||
if(canExistPoint == 1) { | ||
map[pr][pc] = (char) (k + '0'); | ||
// 숫자 입력하고 가로, 세로 표시 남기기 | ||
markCross(pr, pc, k); | ||
// 구역에 해당 숫자 저장해주기 | ||
set[idx].add(k); | ||
// map에 입력한 숫자 개수 + 1 | ||
putCnt += 1; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// map에 입력한 숫자가 없다면 더이상 스도쿠 탐색 끝! | ||
if(putCnt == 0) break; | ||
|
||
} | ||
return !error; | ||
} | ||
|
||
static String printMap() { | ||
StringBuilder sb = new StringBuilder(); | ||
for(int r = 0; r < map.length; r++) { | ||
for(int c = 0; c < map[0].length; c++) sb.append(map[r][c]); | ||
sb.append("\n"); | ||
} | ||
|
||
return sb.toString(); | ||
} | ||
|
||
static void initInput() throws Exception { | ||
System.setIn(new FileInputStream("./input/BOJ2955.txt")); | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
v = new boolean[10][9][9]; | ||
map = new char[9][9]; | ||
set = new HashSet[9]; | ||
|
||
for(int i = 0; i < 9; i++) set[i] = new HashSet<Integer>(); | ||
for(int r = 0; r < map.length; r++) { | ||
String s = br.readLine(); | ||
for(int c = 0; c < map[0].length; c++) { | ||
map[r][c] = s.charAt(c); | ||
|
||
if(map[r][c] == '.') continue; | ||
int num = map[r][c] - '0'; | ||
|
||
// map을 입력받으면서 숫자가 입력받은 지점 기준 가로, 세로 표시 남기기 | ||
markCross(r, c, num); | ||
|
||
// map을 3 X 3으로 나누었을 때, 해당 칸에 어떤 수가 저장되어 있는지 저장 | ||
// 숫자를 입력 받았는데, 해당 구역에 이미 그 숫자가 있으면 모순이 일어나는 스도쿠 | ||
if(!putNumSet(r, c, num)) error = true; | ||
} | ||
} | ||
} | ||
|
||
static boolean putNumSet(int r, int c, int num) { | ||
int idx = (r / 3) * 3 + c / 3; | ||
if(set[idx].contains(num)) return false; | ||
set[idx].add(num); | ||
return true; | ||
} | ||
|
||
static void markCross(int r, int c, int num) { | ||
for(int rr = 0; rr < 9; rr++) v[num][rr][c] = true; | ||
for(int cc = 0; cc < 9; cc++) v[num][r][cc] = true; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.