-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
329 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
84 changes: 84 additions & 0 deletions
84
BOJ-ios/μ€μν/P2672λ²_μ¬λ¬_μ§μ¬κ°νμ_μ 체_λ©΄μ _ꡬνκΈ°/Main.java
This file contains 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,84 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.StringTokenizer; | ||
|
||
public class Main { | ||
static class RectangleEvent implements Comparable<RectangleEvent> { | ||
int x; | ||
int yUp; | ||
int yDown; | ||
int chk; | ||
|
||
public RectangleEvent(int x, int yDown, int yUp, int chk) { | ||
this.x = x; | ||
this.yUp = yUp; | ||
this.yDown = yDown; | ||
this.chk = chk; | ||
} | ||
|
||
@Override | ||
public int compareTo(RectangleEvent o) { | ||
if (this.x == o.x) | ||
return this.chk - o.chk; | ||
return this.x - o.x; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
RectangleEvent that = (RectangleEvent) obj; | ||
return this.x == that.x && this.yUp == that.yUp && this.yDown == that.yDown && this.chk == that.chk; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(x, yUp, yDown, chk); | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = null; | ||
int n = Integer.parseInt(br.readLine()); | ||
List<RectangleEvent> events = new ArrayList<>(); | ||
int[] sweep = new int[20001]; | ||
while (n-- > 0) { | ||
st = new StringTokenizer(br.readLine()); | ||
int xStart = (int) (Double.parseDouble(st.nextToken()) * 10); | ||
int yDown = (int) (Double.parseDouble(st.nextToken()) * 10); | ||
int xEnd = xStart + (int) (Double.parseDouble(st.nextToken()) * 10); | ||
int height = (int) (Double.parseDouble(st.nextToken()) * 10); | ||
int yUp = yDown + height; | ||
events.add(new RectangleEvent(xStart, yDown, yUp, 1)); | ||
events.add(new RectangleEvent(xEnd, yDown, yUp, -1)); | ||
} | ||
Collections.sort(events); | ||
int area = 0; | ||
int x = 0; | ||
for (RectangleEvent event : events) { | ||
int count = 0; | ||
for (int i = 0; i < 20001; i++) | ||
if (sweep[i] > 0) | ||
count++; | ||
area += count * (event.x - x); | ||
for (int i = event.yDown; i < event.yUp; i++) { | ||
if (event.chk == 1) | ||
sweep[i]++; | ||
else | ||
sweep[i]--; | ||
} | ||
x = event.x; | ||
} | ||
System.out.println(area % 100 == 0 ? (int) (area * 0.01) : String.format("%.2f", area * 0.01)); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
## βοΈ κΈ°λ‘ | ||
|
||
| μ°¨μ | λ μ§ | λ¬Έμ μ ν | λ§ν¬ | νμ΄ | | ||
|:---:|:----------:|:----:|:-----------------------------------------------:|:--------------------------------------------------------:| | ||
| μ°¨μ | λ μ§ | λ¬Έμ μ ν | λ§ν¬ | νμ΄ | | ||
|:---:|:----------:|:----:|:---------------------------------------------------:|:--------------------------------------------------------:| | ||
| 1μ°¨μ | 2024.03.18 | ꡬν | [μ΄μ°¨μ λ°°μ΄κ³Ό μ°μ°](https://www.acmicpc.net/problem/17140) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/5) | | ||
| 2μ°¨μ | 2024.03.22 | μ€ν | [ν€λ‘κ±°](https://www.acmicpc.net/problem/5397) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/7) | | ||
| 3μ°¨μ | 2024.03.26 | DP | [μ±](https://www.acmicpc.net/problem/7579) | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/11) | | ||
| 2μ°¨μ | 2024.03.22 | μ€ν | [ν€λ‘κ±°](https://www.acmicpc.net/problem/5397) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/7) | | ||
| 3μ°¨μ | 2024.03.26 | DP | [μ±](https://www.acmicpc.net/problem/7579) | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/11) | | ||
| 4μ°¨μ | 2024.03.30 | κ·Έλν | [νμΆ](https://www.acmicpc.net/problem/3055) | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/16) | |
This file contains 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,123 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayDeque; | ||
import java.util.ArrayList; | ||
import java.util.Queue; | ||
import java.util.StringTokenizer; | ||
|
||
public class BOJ3055 { | ||
static int r, c; | ||
static int startX, startY, endX, endY; | ||
static char[][] map; | ||
static boolean[][] visited; | ||
static boolean[][] waterVisited; | ||
static int[] dx = {1, -1, 0, 0}; | ||
static int[] dy = {0, 0, -1, 1}; | ||
static ArrayDeque<Node> water; | ||
public static void main(String[] args) throws IOException { | ||
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]; | ||
visited = new boolean[r][c]; | ||
waterVisited = new boolean[r][c]; | ||
water = new ArrayDeque<Node>(); | ||
|
||
for (int i = 0; i < r; i++) { | ||
String tmp = br.readLine(); | ||
for (int j = 0; j < c; j++) { | ||
map[i][j] = tmp.charAt(j); | ||
if (map[i][j] == 'S') { | ||
startX = i; | ||
startY = j; | ||
} else if (map[i][j] == 'D') { | ||
endX = i; | ||
endY = j; | ||
} else if (map[i][j] == '*') { | ||
water.add(new Node(i, j, 0)); | ||
} | ||
} | ||
} | ||
|
||
bfs(startX, startY); | ||
} | ||
|
||
private static void bfs(int x, int y) { | ||
Queue<Node> queue = new ArrayDeque<>(); // λλμ§κ° κ°λ κ²½λ‘λ§ λ΄λλ€ | ||
queue.add(new Node(x, y, 0)); // μΆλ°μ§μ λ£κ³ | ||
visited[x][y] = true; | ||
|
||
while (!queue.isEmpty()) { | ||
// λ¬Όμ νΌλ¨λ¦° ν κ³ μ΄λμΉ μ΄λ -> κ³ μ΄λμΉλ λ¬Όμ ν΅κ³Ό λͺ»νλ€. | ||
int size = queue.size(); | ||
for (int s = 0; s < size; s++) { | ||
Node curr = queue.poll(); | ||
int currX = curr.x; | ||
int currY = curr.y; | ||
int currCnt = curr.count; | ||
if (map[currX][currY] == '*') | ||
continue; | ||
|
||
// κΈ°μ | ||
if (map[currX][currY] == 'D') { | ||
System.out.println(currCnt); | ||
return; | ||
} | ||
for (int i = 0; i < 4; i++) { | ||
int nx = dx[i] + currX; | ||
int ny = dy[i] + currY; | ||
if (nx >= 0 && ny >= 0 && nx < r && ny < c && !visited[nx][ny]) { | ||
// κ³ μ΄λμΉκ° κ°λ €λ μ리μ λ¬Όμ΄λ λμ΄ μμΌλ©΄ | ||
if (map[nx][ny] == '*' || map[nx][ny] == 'X') continue; | ||
visited[nx][ny] = true; | ||
|
||
queue.add(new Node(nx, ny, currCnt+1)); | ||
|
||
} | ||
} | ||
|
||
} | ||
// μ°μ λ¬ΌλΆν° νΌλ¨λ¦°λ€. -> λ¬Όμ λκ³Ό μκ΅΄μ΄ μλ μ리, Dλ‘λ νΌμ§ μ μλ€. | ||
int waterSize = water.size(); | ||
for (int i = 0; i < waterSize; i++) { | ||
Node waters = water.poll(); | ||
int waterX = waters.x; | ||
int waterY = waters.y; | ||
//int waterCnt = waters.count; | ||
// κ°λ €λ κ³³μ΄ λμ΄ μλκ³ λΉλ²μ κ΅΄μ΄ μλλ | ||
for (int j = 0; j < 4; j++) { | ||
int nx = dx[j] + waterX; | ||
int ny = dy[j] + waterY; | ||
if (nx >= 0 && ny >= 0 && nx < r && ny < c) { | ||
// λμ΄μλκ³ κ΅΄μ΄ μλμ¬μΌν¨ | ||
if (map[nx][ny] == 'X' || map[nx][ny] == 'D' || waterVisited[nx][ny]) continue; | ||
// κ° μ μλ κ³³μ΄λΌλ©΄ | ||
|
||
map[nx][ny] = '*'; | ||
waterVisited[nx][ny] = true; | ||
water.add(new Node(nx, ny, 0)); | ||
|
||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
System.out.println("KAKTUS"); | ||
|
||
|
||
|
||
|
||
} | ||
|
||
static class Node { | ||
private int x, y, count; | ||
public Node (int x, int y, int count) { | ||
this.x = x; | ||
this.y = y; | ||
this.count = count; | ||
} | ||
} | ||
} |
This file contains 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,38 @@ | ||
from collections import deque | ||
|
||
N, M = map(int, input().split()) | ||
|
||
graph = [] | ||
|
||
for _ in range(N): | ||
graph.append(list(map(int, input()))) | ||
|
||
def BFS(x, y): | ||
# μ΄λν μ, ν, μ’, μ° λ°©ν₯ μ μ | ||
dx = [-1,1,0,0] | ||
dy = [0,0,-1,1] | ||
|
||
queue = deque() | ||
queue.append((x,y)) | ||
|
||
while queue: | ||
x, y = queue.popleft() | ||
|
||
for i in range(4): | ||
nx = x + dx[i] | ||
ny = y + dy[i] | ||
|
||
if nx<0 or nx>=N or ny<0 or ny>=M: | ||
continue | ||
|
||
if graph[nx][ny]==0: | ||
continue | ||
|
||
if graph[nx][ny]==1: | ||
graph[nx][ny] = graph[x][y]+1 | ||
queue.append((nx,ny)) | ||
|
||
|
||
return graph[N-1][M-1] | ||
|
||
print(BFS(0,0)) |
This file contains 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,35 @@ | ||
#μ λ ₯κ° λ°λ λΆλΆ | ||
n=int(input()) | ||
a,b=map(int,input().split()) | ||
m=int(input()) | ||
|
||
#κΈ°λ³Έ μ μΈ | ||
graph=[[] for _ in range(n+1)] #λ Έλμ λ²νΈμ λ°°μ΄ λ²νΈ ν΅μΌμν€κΈ° μν΄μ nμ΄ μλ n+1 μ¬μ© | ||
visited=[[False]*(n+1)] | ||
result=[] | ||
|
||
|
||
for _ in range(m): | ||
x,y=map(int, input().split()) | ||
graph[x].append(y) | ||
graph[y].append(x) | ||
|
||
|
||
|
||
def dfs(v,num): | ||
num+=1 | ||
visited[v]=True | ||
|
||
if v==b: | ||
result.append(num) | ||
|
||
for i in graph[v]: | ||
if not visited[i]: | ||
dfs(i,num) | ||
|
||
dfs(a,0) | ||
|
||
if len(result)==0: | ||
print(-1) | ||
else: | ||
print(result) |
This file contains 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
This file contains 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
This file contains 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,38 @@ | ||
import sys | ||
from collections import deque | ||
input = sys.stdin.readline | ||
|
||
sum = 0 | ||
cnt = 0 | ||
n = int(input()) | ||
max_height = 0 | ||
board = [list(map(int, input().split())) for _ in range(n)] | ||
|
||
max_height = max(map(max, board)) | ||
|
||
def bfs(x, y, k): | ||
dx, dy = [-1, 0, 1, 0], [0, 1, 0, -1] | ||
q = deque() | ||
q.append((x, y)) | ||
|
||
while q: | ||
x, y = q.popleft() | ||
for i in range(4): | ||
nx, ny = x + dx[i], y + dy[i] | ||
if 0 <= nx < n and 0 <= ny < n and visited[nx][ny] == 0 and board[nx][ny] > k: | ||
visited[nx][ny] = 1 | ||
q.append((nx, ny)) | ||
|
||
|
||
for k in range(max_height): | ||
visited = [[0] * n for _ in range(n)] | ||
cnt = 0 | ||
|
||
for i in range(n): | ||
for j in range(n): | ||
if visited[i][j] == 0 and board[i][j] > k: | ||
bfs(i, j, k) | ||
cnt += 1 | ||
sum = max(sum, cnt) | ||
|
||
print(sum) |