Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[10주차] 이지영 #135

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
yeongleej merged 9 commits into GreatAlgorithm-Study:main from yeongleej:main
Nov 17, 2024
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
68 changes: 68 additions & 0 deletions BOJ/1000-5000번/JY_1613.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package day1113;

import java.io.*;
import java.util.*;

public class JY_1613 {

static final int INF = 50_000;

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

int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());

int[][] g = new int[N+1][N+1];
for(int i=0; i<N+1; i++) {
Arrays.fill(g[i], INF);
}
// 자신으로가는 비용은 0으로 처리
for(int i=1; i<N+1; i++) {
for(int j=1; j<N+1; j++) {
if(i == j) g[i][j] = 0;
}
}

for(int i=0; i<K; i++) {
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());

g[a][b] = 1;
}

// 플로이드 와샬: i -> j로 갈 수 있는 최단거리 구함
for(int k=1; k<N+1; k++) {
for(int i=1; i<N+1; i++) {
for(int j=1; j<N+1; j++) {
g[i][j] = Math.min(g[i][j], g[i][k]+g[k][j]);
}
}
}


st = new StringTokenizer(br.readLine());
int S = Integer.parseInt(st.nextToken());

StringBuilder sb = new StringBuilder();
for(int s=0; s<S; s++) {
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());

if(g[a][b] != INF) {
sb.append("-1\n");
} else if(g[b][a] != INF) {
sb.append("1\n");
} else {
sb.append("0\n");
}
}

System.out.println(sb.toString());

}

}
46 changes: 46 additions & 0 deletions BOJ/1000-5000번/JY_2096.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package day1113;

import java.io.*;
import java.util.*;

public class JY_2096 {

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

int N = Integer.parseInt(st.nextToken());
int[][] dp1 = new int[N][3];
int[][] dp2 = new int[N][3];

for(int i=0; i<N; i++) {
st = new StringTokenizer(br.readLine());
dp1[i][0] = Integer.parseInt(st.nextToken());
dp1[i][1] = Integer.parseInt(st.nextToken());
dp1[i][2] = Integer.parseInt(st.nextToken());
}

for(int i=0; i<N; i++) {
dp2[i][0] = dp1[i][0];
dp2[i][1] = dp1[i][1];
dp2[i][2] = dp1[i][2];
}

for(int i=1; i<N; i++) {
dp1[i][0] = dp1[i][0] + Math.min(dp1[i-1][0], dp1[i-1][1]);
dp1[i][1] = dp1[i][1] + Math.min(dp1[i-1][0], Math.min(dp1[i-1][1], dp1[i-1][2]));
dp1[i][2] = dp1[i][2] + Math.min(dp1[i-1][1], dp1[i-1][2]);

dp2[i][0] = dp2[i][0] + Math.max(dp2[i-1][0], dp2[i-1][1]);
dp2[i][1] = dp2[i][1] + Math.max(dp2[i-1][0], Math.max(dp2[i-1][1], dp2[i-1][2]));
dp2[i][2] = dp2[i][2] + Math.max(dp2[i-1][1], dp2[i-1][2]);
}

int max = Math.max(dp2[N-1][0], Math.max(dp2[N-1][1], dp2[N-1][2]));
int min = Math.min(dp1[N-1][0], Math.min(dp1[N-1][1], dp1[N-1][2]));

System.out.println(max+" "+min);

}

}
194 changes: 194 additions & 0 deletions BOJ/1000-5000번/JY_2955.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
package day1112;

import java.io.*;
import java.util.*;

public class JY_2955 {

static final int N = 9;
static int[][] g;
static boolean[][] visited;

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

g = new int[N][N];
for(int i=0; i<N; i++) {
String s = br.readLine();
for(int j=0; j<N; j++) {
if(s.charAt(j) == '.') {
g[i][j] = 0;
} else {
g[i][j] = s.charAt(j) - '0';
}
}
}



// cross hatching
while(true) {
boolean isDone = true;

for(int n=1; n<=9; n++) {
// 유효성 체크
if(!isValid(n)) {
System.out.println("ERROR");
return;
}
int cnt = crossHatching(n);
if(cnt > 0) isDone = false;
}

if(isDone) break;

}

printS();

}
public static void printG() {
for(int i=0; i<N; i++) {
System.out.println(Arrays.toString(g[i]));
}
System.out.println();
}
public static void printV() {
for(int i=0; i<N; i++) {
System.out.println(Arrays.toString(visited[i]));
}
System.out.println();
}
public static void printS() {
for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) {
if(g[i][j] == 0) System.out.print(".");
else System.out.print(g[i][j]);
}
System.out.println();
}
}
public static void fillLine(int x, int y) {
// 세로줄
for(int i=0; i<N; i++) {
visited[i][y] = true;
}

// 가로줄
for(int j=0; j<N; j++) {
visited[x][j] = true;
}

}
public static void fillSquare(int sx, int sy) {
// 3*3
for(int i=sx; i<sx+3; i++) {
for(int j=sy; j<sy+3; j++) {
visited[i][j] = true;
}
}
}
public static void fillArea(int n) {
for(int i=0; i<N; i += 3) {
for(int j=0; j<N; j += 3) {
for(int x=i; x<i+3; x++) {
for(int y=j; y<j+3; y++) {
if(g[x][y] == n) {
fillLine(x, y);
fillSquare(i, j);
}
if(g[x][y] != 0) {
visited[x][y] = true;
}
}
}
}
}
}
public static boolean checkLine(int n) {
for(int x=0; x<N; x++) {
for(int y=0; y<N; y++) {
if(g[x][y] != n) continue;

// 세로줄 체크
int cnt = 0;
for(int i=0; i<N; i++) {
if(g[i][y] == n) cnt++;
}
if(cnt > 1) return false;

// 기로즐 체크
cnt = 0;
for(int j=0; j<N; j++) {
if(g[x][j] == n) cnt++;
}
if(cnt > 1) return false;

}
}
return true;
}
public static boolean checkBox(int n) {
// 유효한 3 * 3 찾기
for(int i=0; i<N; i+=3) {
for(int j=0; j<N; j += 3) {
int cnt = 0;
int empty = 0;
for(int x=i; x<i+3; x++) {
for(int y=j; y<j+3; y++) {
if(g[x][y] == n) cnt++;
if(!visited[x][y]) empty++;
}
}

if(cnt > 1) return false;
if(cnt == 0 && empty == 0) return false;
}
}
return true;
}
public static boolean isValid(int n) {
visited = new boolean[N][N];

fillArea(n);

return checkBox(n) && checkLine(n);
}
public static int findSpot(int n) {
// 유효한 3 * 3 찾기
int fCnt = 0;
for(int i=0; i<N; i+=3) {
for(int j=0; j<N; j += 3) {
int cnt = 0;
int empty = 0;
int px = -1, py = -1;
for(int x=i; x<i+3; x++) {
for(int y=j; y<j+3; y++) {
if(g[x][y] == n) cnt++;
if(!visited[x][y]) {
empty++;
px = x;
py = y;
}
}
}
// n이없고, 빈곳이 1개이면 => CrossHatching
if(cnt == 0 && empty == 1) {
visited[px][py] = true;
g[px][py] = n;
fillLine(px, py);
fCnt++;
}
}
}
return fCnt;
}
public static int crossHatching(int n) {
visited = new boolean[N][N];
fillArea(n);


return findSpot(n);
}

}
Loading

AltStyle によって変換されたページ (->オリジナル) /