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

Commit ae6f049

Browse files
Merge pull request #261 from yeongleej/main
[19μ£Όμ°¨] μ΄μ§€μ˜
2 parents b53b618 + b167f9a commit ae6f049

File tree

4 files changed

+286
-0
lines changed

4 files changed

+286
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class JY_1405 {
5+
6+
static int N, M;
7+
static double[] arr;
8+
static boolean[][] visited;
9+
// 동 μ„œ 남 뢁
10+
static int[] dx = {0, 0, 1, -1};
11+
static int[] dy = {1, -1, 0, 0};
12+
static double ans;
13+
14+
public static void main(String[] args) throws IOException {
15+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
16+
StringTokenizer st = new StringTokenizer(br.readLine());
17+
18+
N = Integer.parseInt(st.nextToken());
19+
20+
arr = new double[4];
21+
for(int i=0; i<4; i++) {
22+
arr[i] = Integer.parseInt(st.nextToken()) * 0.01;
23+
}
24+
25+
// N <= 14 μ΄λ―€λ‘œ μƒν•˜μ’Œμš° λ°©ν–₯으둜 μ΅œλŒ€ 14κΉŒμ§€ 갈 수 μžˆμœΌλ―€λ‘œ λ³΄λ“œνŒ 크기: 30
26+
M = 30;
27+
visited = new boolean[M][M];
28+
visited[M/2][M/2] = true;
29+
ans = 0;
30+
dfs(M/2, M/2, 0, 1);
31+
32+
System.out.println(ans);
33+
}
34+
public static boolean inRange(int x, int y) {
35+
return x>=0 && x<M && y>=0 && y<M;
36+
}
37+
public static void dfs(int x, int y, int cnt, double total) {
38+
if(cnt == N) {
39+
ans += total;
40+
return;
41+
}
42+
43+
for(int i=0; i<4; i++) {
44+
int nx = x + dx[i];
45+
int ny = y + dy[i];
46+
47+
if(!inRange(nx, ny)) continue;
48+
if(visited[nx][ny]) continue;
49+
50+
visited[nx][ny] = true;
51+
dfs(nx, ny, cnt+1, total*arr[i]);
52+
visited[nx][ny] = false;
53+
}
54+
}
55+
56+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class JY_1938 {
5+
6+
static int N;
7+
static char[][] g;
8+
// 상, 쒌, ν•˜, 우
9+
static int[] dx = {-1, 0, 1, 0};
10+
static int[] dy = {0, -1, 0, 1};
11+
static int ans;
12+
static class Step {
13+
int x, y;
14+
int dir; // μ„Έλ‘œ: 0, κ°€λ‘œ: 1
15+
int cnt;
16+
public Step(int x, int y, int dir, int cnt) {
17+
super();
18+
this.x = x;
19+
this.y = y;
20+
this.dir = dir;
21+
this.cnt = cnt;
22+
}
23+
@Override
24+
public String toString() {
25+
return "Step [x=" + x + ", y=" + y + ", dir=" + dir + ", cnt=" + cnt + "]";
26+
}
27+
28+
}
29+
30+
31+
public static void main(String[] args) throws IOException {
32+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
33+
StringTokenizer st = new StringTokenizer(br.readLine());
34+
35+
N = Integer.parseInt(st.nextToken());
36+
g = new char[N][N];
37+
38+
List<int[]> bList = new ArrayList<>();
39+
for(int i=0; i<N; i++) {
40+
String line = br.readLine();
41+
for(int j=0; j<N; j++) {
42+
g[i][j] = line.charAt(j);
43+
44+
if(g[i][j] == 'B') {
45+
g[i][j] = '0';
46+
bList.add(new int[] {i, j});
47+
}
48+
}
49+
}
50+
51+
// 초기 λ‚˜λ¬΄ κ°€λ‘œ or μ„Έλ‘œμΈμ§€ μ°ΎκΈ°
52+
int cDir = -1;
53+
int[] t = bList.get(0);
54+
int[] c = bList.get(1);
55+
// μ„Έλ‘œμΈκ°€? (cDir =0: μ„Έλ‘œ, cDir=1: κ°€λ‘œ)
56+
if(c[0]+dx[0] == t[0] && c[1]+dy[0] == t[1]) {
57+
cDir = 0;
58+
} else {
59+
cDir = 1;
60+
}
61+
62+
63+
ans = 0;
64+
bfs(c[0], c[1], cDir);
65+
66+
System.out.println(ans);
67+
68+
}
69+
public static boolean inRange(int x, int y) {
70+
return x>=0 && x<N && y>=0 && y<N;
71+
}
72+
public static boolean isExit(int x, int y, int dir) {
73+
int ax = x + dx[dir];
74+
int ay = y + dy[dir];
75+
int bx = x + dx[dir+2];
76+
int by = y + dy[dir+2];
77+
78+
return (g[ax][ay]=='E') && (g[x][y]=='E') && (g[bx][by] =='E');
79+
80+
}
81+
public static void bfs(int sx, int sy, int sDir) {
82+
// 방문처리: (i,j)μ’Œν‘œμ— 쀑심점이 μ„Έλ‘œ(0) or κ°€λ‘œ(1)둜 λ°©λ¬Έν•œμ μ΄ μžˆλŠ”μ§€ 체크
83+
boolean[][][] visited = new boolean[N][N][2];
84+
Queue<Step> q = new LinkedList<>();
85+
86+
q.add(new Step(sx, sy, sDir, 0));
87+
visited[sx][sy][sDir] = true;
88+
89+
while(!q.isEmpty()) {
90+
Step now = q.poll();
91+
92+
if(isExit(now.x, now.y, now.dir)) {
93+
ans = now.cnt;
94+
break;
95+
}
96+
97+
// U, L, D, R
98+
for(int i=0; i<4; i++) {
99+
int nx = now.x + dx[i];
100+
int ny = now.y + dy[i];
101+
102+
// 쀑심 ν†΅λ‚˜λ¬΄ 체크
103+
if(!inRange(nx, ny)) continue;
104+
if(visited[nx][ny][now.dir]) continue;
105+
if(g[nx][ny] == '1') continue;
106+
107+
108+
// λ‚˜λ¨Έμ§€ ν†΅λ‚˜λ¬΄λ“€ 체크
109+
int ax = nx + dx[now.dir];
110+
int ay = ny + dy[now.dir];
111+
int bx = nx + dx[now.dir+2];
112+
int by = ny + dy[now.dir+2];
113+
if(!inRange(ax, ay) || !inRange(bx, by)) continue;
114+
if(g[ax][ay] == '1' || g[bx][by] == '1') continue;
115+
116+
// 이동가λŠ₯
117+
visited[nx][ny][now.dir] = true;
118+
q.add(new Step(nx, ny, now.dir, now.cnt+1));
119+
}
120+
121+
if(!canTurn(now.x, now.y)) continue;
122+
// turn
123+
int nDir = Math.abs(now.dir-1);
124+
if(visited[now.x][now.y][nDir]) continue; // νšŒμ „ν•œ λ°©ν–₯으둜 νšŒμ „ν•œ 적이 있음
125+
int ax = now.x + dx[nDir];
126+
int ay = now.y + dy[nDir];
127+
int bx = now.x + dx[nDir+2];
128+
int by = now.y + dy[nDir+2];
129+
if(!inRange(ax, ay) || !inRange(bx, by)) continue;
130+
if(g[ax][ay] == '1' || g[bx][by] == '1') continue;
131+
132+
visited[now.x][now.y][nDir] = true;
133+
q.add(new Step(now.x, now.y, nDir, now.cnt+1));
134+
}
135+
136+
}
137+
public static boolean canTurn(int x, int y) {
138+
for(int i=x-1; i<x+2; i++) {
139+
for(int j=y-1; j<y+2; j++) {
140+
if(!inRange(i, j)) return false;
141+
if(g[i][j] == '1') return false;
142+
}
143+
}
144+
return true;
145+
}
146+
147+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class JY_13334 {
5+
6+
static int N;
7+
static long D;
8+
static class Pos implements Comparable<Pos>{
9+
long h, o;
10+
11+
public Pos(long h, long o) {
12+
super();
13+
this.h = h;
14+
this.o = o;
15+
}
16+
17+
// 끝점 κΈ°μ€€μœΌλ‘œ μ •λ ¬
18+
@Override
19+
public int compareTo(Pos other) {
20+
return (int)(this.o - other.o);
21+
}
22+
23+
@Override
24+
public String toString() {
25+
return "Pos [h=" + h + ", o=" + o + "]";
26+
}
27+
28+
}
29+
30+
31+
public static void main(String[] args) throws IOException {
32+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
33+
StringTokenizer st = new StringTokenizer(br.readLine());
34+
35+
N = Integer.parseInt(st.nextToken());
36+
37+
// 끝점이 μž‘μ€ 순으둜 μ •λ ¬ => μ‹œμž‘μ λ§Œ 신경쓰면됨
38+
// λ°˜λŒ€λ‘œ) μ‹œμž‘μ  κΈ°μ€€μœΌλ‘œ μ •λ ¬ν•˜λ©΄, μ‹œμž‘μ μ΄ 이동할 λ•Œ 이전 κ²ƒλ“€μ˜ μ‹œμž‘μ , 끝점을 λͺ¨λ‘ μ‹ κ²½μ¨μ€˜μ•Ό 함
39+
PriorityQueue<Pos> pq = new PriorityQueue<>();
40+
for(int i=0; i<N; i++) {
41+
st = new StringTokenizer(br.readLine());
42+
long h = Long.parseLong(st.nextToken());
43+
long o = Long.parseLong(st.nextToken());
44+
45+
if(h <= o) {
46+
pq.add(new Pos(h, o));
47+
} else {
48+
pq.add(new Pos(o, h));
49+
}
50+
51+
}
52+
53+
D = Long.parseLong(br.readLine());
54+
55+
int ans = 0;
56+
PriorityQueue<Long> tpq = new PriorityQueue<>();
57+
while(!pq.isEmpty()) {
58+
Pos now = pq.poll();
59+
long start = now.o - D;
60+
tpq.add(now.h);
61+
62+
while(!tpq.isEmpty() && tpq.peek() < start) {
63+
// ν˜„μž¬ μ‹œμž‘μ§€μ  보닀 μž‘μ€ μ‹œμž‘μ λ“€μ€ ν˜„μž¬ ꡬ간에 포함될 수 μ—†μŒ
64+
tpq.poll();
65+
}
66+
67+
ans = Math.max(ans, tpq.size());
68+
}
69+
70+
System.out.println(ans);
71+
72+
}
73+
74+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- 1193. Monthly Transactions I
2+
-- https://leetcode.com/problems/monthly-transactions-i/
3+
SELECT DATE_FORMAT(trans_date, "%Y-%m") AS month, country
4+
, COUNT(*) AS trans_count
5+
, COUNT(IF(state = 'approved', state, NULL)) AS approved_count
6+
, SUM(amount) AS trans_total_amount
7+
, SUM(IF(state = 'approved', amount, 0)) AS approved_total_amount
8+
FROM TRANSACTIONS
9+
GROUP BY YEAR(trans_date), MONTH(trans_date), country

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /