-
Notifications
You must be signed in to change notification settings - Fork 4
[17주차] 고다혜 #233
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
[17주차] 고다혜 #233
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f946528
고다혜: [BOJ] 2258 정육점_240101
KodaHye ac14834
고다혜: [BOJ] 20061 모노미노도미노 2_240107
KodaHye 2bc5ee2
고다혜: [BOJ] 3109 빵집_240107
KodaHye 418ebf3
고다혜: [PG] 86052 빛의 경로 사이클_240108
KodaHye dc19995
고다혜: [SQL] 1765 닭싸움 팀 정하기_240109
KodaHye 4945467
고다혜: [PG] 12905 가장 큰 정사각형_240109
KodaHye 52c845d
고다혜: [PG] 258711 도넛과 막대 그래프_240108
KodaHye 078c2b1
고다혜: [SQL] Odd and Even_240109
KodaHye 0d045e5
고다혜: [SQL] Restaurant Growth_240107
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
83 changes: 83 additions & 0 deletions
BOJ/1000-5000번/DH_1765.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,83 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
/* | ||
* 닭싸움 팀 정하기 | ||
*/ | ||
|
||
public class DH_1765 { | ||
static class Node { | ||
int e; | ||
boolean isFriend; | ||
|
||
public Node(int e, boolean isFriend) { | ||
this.e = e; | ||
this.isFriend = isFriend; | ||
} | ||
} | ||
static boolean[] check; | ||
static ArrayList<Node> adj[]; | ||
static int groupCnt; | ||
|
||
public static void main(String[] args) throws Exception { | ||
initInput(); | ||
solution(); | ||
} | ||
|
||
static void solution() { | ||
for(int i = 1; i < check.length; i++) { | ||
if(check[i]) continue; | ||
groupCnt += 1; | ||
dfs(i); | ||
} | ||
|
||
System.out.println(groupCnt); | ||
} | ||
|
||
static void dfs(int node) { | ||
check[node] = true; | ||
|
||
for(Node next: adj[node]) { | ||
// 현재 사람의 바로 옆 사람이 친구라면 같은 팀을 할 수 있음 | ||
if(next.isFriend) { | ||
|
||
if(check[next.e]) continue; | ||
dfs(next.e); | ||
|
||
} | ||
// 현재 사람의 바로 옆 사람이 원수라면 | ||
else { | ||
// 옆사람과 옆옆사람이 원수일 때, 현재 사람과 같은 팀을 할 수 있음 | ||
for(Node nnext: adj[next.e]) { | ||
if(check[nnext.e] || nnext.isFriend) continue; | ||
dfs(nnext.e); | ||
} | ||
} | ||
} | ||
} | ||
|
||
static void initInput() throws Exception { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
|
||
int n = Integer.parseInt(br.readLine()); | ||
check = new boolean[n + 1]; | ||
adj = new ArrayList[n + 1]; | ||
|
||
for(int i = 0; i < adj.length; i++) adj[i] = new ArrayList<Node>(); | ||
|
||
int m = Integer.parseInt(br.readLine()); | ||
|
||
for(int i = 0; i < m; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
|
||
boolean isFriend = st.nextToken().charAt(0) == 'F'; | ||
|
||
int p = Integer.parseInt(st.nextToken()); | ||
int q = Integer.parseInt(st.nextToken()); | ||
|
||
adj[p].add(new Node(q, isFriend)); | ||
adj[q].add(new Node(p, isFriend)); | ||
} | ||
} | ||
} |
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
71 changes: 71 additions & 0 deletions
BOJ/1000-5000번/DH_3109.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,71 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
/* | ||
* 빵집 | ||
*/ | ||
|
||
public class DH_3109 { | ||
static int[] dr = {-1, 0, 1}, dc = {1, 1, 1}; | ||
static int R, C, cnt; | ||
static char[][] map; | ||
static boolean flag; | ||
|
||
public static void main(String[] args) throws Exception { | ||
initInput(); | ||
solution(); | ||
|
||
System.out.println(cnt); | ||
} | ||
|
||
static void solution() { | ||
for(int r = 0; r < R; r++) { | ||
flag = false; | ||
dfs(r, 0); // (r, 0)에서 dfs 시작 | ||
} | ||
} | ||
|
||
static void dfs(int r, int c) { | ||
if(c == C - 1) { | ||
cnt += 1; | ||
flag = true; | ||
return; | ||
} | ||
|
||
for(int d = 0; d < 3; d++) { | ||
int nr = r + dr[d]; | ||
int nc = c + dc[d]; | ||
|
||
if(!check(nr, nc) || map[nr][nc] == 'x' || flag) continue; | ||
map[nr][nc] = 'x'; | ||
dfs(nr, nc); | ||
} | ||
} | ||
|
||
static boolean check(int r, int c) { | ||
return r >= 0 && r < R && c >= 0 && c < C; | ||
} | ||
|
||
static void initInput() throws Exception { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
R= Integer.parseInt(st.nextToken()); | ||
C = Integer.parseInt(st.nextToken()); | ||
|
||
map = new char[R][C]; | ||
|
||
for(int r = 0; r < R; r++) { | ||
String str = br.readLine(); | ||
map[r] = str.toCharArray(); | ||
} | ||
} | ||
|
||
static void printMap(char[][] map) { | ||
for(int r = 0; r < map.length; r++) { | ||
System.out.println(Arrays.toString(map[r])); | ||
} | ||
|
||
System.out.println(); | ||
} | ||
} |
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.