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 14f4875

Browse files
Merge pull request #5 from yeongleej/main
[1์ฃผ์ฐจ] ์ด์ง€์˜
2 parents 764d8b6 + f505e21 commit 14f4875

10 files changed

+590
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package day0910;
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
public class JY_2531 {
7+
8+
public static void main(String[] args) throws IOException{
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
StringTokenizer st = new StringTokenizer(br.readLine());
11+
12+
int N = Integer.parseInt(st.nextToken());
13+
int D = Integer.parseInt(st.nextToken());
14+
int K = Integer.parseInt(st.nextToken());
15+
int C = Integer.parseInt(st.nextToken());
16+
17+
int[] arr = new int[N];
18+
for(int i=0; i<N; i++) {
19+
st = new StringTokenizer(br.readLine());
20+
arr[i] = Integer.parseInt(st.nextToken());
21+
}
22+
23+
// System.out.println(Arrays.toString(arr));
24+
25+
Map<Integer, Integer> cMap = new HashMap<>();
26+
// ์ดˆ๊ธฐํ™”
27+
for(int i=0; i<K; i++) {
28+
if(cMap.getOrDefault(arr[i], 0) == 0) {
29+
cMap.put(arr[i], 1);
30+
} else {
31+
cMap.put(arr[i], cMap.get(arr[i])+1);
32+
}
33+
}
34+
35+
if(cMap.getOrDefault(C, 0) != 0) {
36+
cMap.put(C, cMap.get(C)+1);
37+
} else {
38+
cMap.put(C, 1);
39+
}
40+
// System.out.println(cMap);
41+
42+
43+
int ans = cMap.keySet().size();
44+
for(int i=0; i<N; i++) {
45+
// arr[i] ์ œ๊ฑฐ
46+
cMap.put(arr[i], cMap.get(arr[i])-1);
47+
if(cMap.get(arr[i]) == 0) {
48+
cMap.remove(arr[i]);
49+
}
50+
// arr[i+K] ์ถ”๊ฐ€
51+
int j = (i+K) % N;
52+
if(cMap.getOrDefault(arr[j], 0) == 0) {
53+
cMap.put(arr[j], 1);
54+
} else {
55+
cMap.put(arr[j], cMap.get(arr[j])+1);
56+
}
57+
// System.out.println(cMap);
58+
59+
ans = Math.max(ans, cMap.keySet().size());
60+
}
61+
System.out.println(ans);
62+
63+
}
64+
65+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package day0911;
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
public class JY_3020 {
7+
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
StringTokenizer st = new StringTokenizer(br.readLine());
11+
12+
int N = Integer.parseInt(st.nextToken());
13+
int H = Integer.parseInt(st.nextToken());
14+
15+
int[] arr = new int[N];
16+
for(int i=0; i<N; i++) {
17+
st = new StringTokenizer(br.readLine());
18+
arr[i] = Integer.parseInt(st.nextToken());
19+
}
20+
// System.out.println(Arrays.toString(arr));
21+
int[] urr = new int[H+2];
22+
int[] drr = new int[H+2];
23+
for(int i=0; i<N; i++) {
24+
// ์„์ˆœ
25+
if(i % 2 == 0) {
26+
urr[1]++;
27+
urr[arr[i]+1]--;
28+
}
29+
// ์ข…์œ ์ˆœ
30+
else {
31+
drr[H]++;
32+
drr[H-arr[i]]--;
33+
}
34+
}
35+
36+
for(int i=1; i<H+2; i++) {
37+
urr[i] += urr[i-1];
38+
}
39+
// System.out.println(Arrays.toString(urr));
40+
for(int i=H-1; i>=0; i--) {
41+
drr[i] += drr[i+1];
42+
}
43+
// System.out.println(Arrays.toString(drr));
44+
45+
int ans = Integer.MAX_VALUE;
46+
int total = 0;
47+
for(int i=1; i<=H; i++) {
48+
if(ans > urr[i]+drr[i]) {
49+
ans = urr[i]+drr[i];
50+
total = 1;
51+
} else if(ans == urr[i]+drr[i]) {
52+
total++;
53+
}
54+
}
55+
System.out.println(ans+" "+total);
56+
57+
58+
}
59+
60+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package day0909;
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
public class JY_์ž์œจ์ฃผํ–‰_์ž๋™์ฐจ {
7+
8+
static int N, M;
9+
static int[][] g;
10+
static Pos now;
11+
static boolean[][] visited;
12+
// ๋ถ, ๋™, ๋‚จ, ์„œ
13+
static int[] dx = {-1, 0, 1, 0};
14+
static int[] dy = {0, 1, 0, -1};
15+
16+
static class Pos {
17+
int x, y, d;
18+
public Pos(int x, int y, int d){
19+
this.x=x;
20+
this.y=y;
21+
this.d=d;
22+
}
23+
@Override
24+
public String toString(){
25+
return this.x+","+this.y+" : "+this.d;
26+
}
27+
}
28+
29+
public static void main(String[] args) throws IOException{
30+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
31+
StringTokenizer st = new StringTokenizer(br.readLine());
32+
33+
N = Integer.parseInt(st.nextToken());
34+
M = Integer.parseInt(st.nextToken());
35+
36+
st = new StringTokenizer(br.readLine());
37+
int nowX = Integer.parseInt(st.nextToken());
38+
int nowY = Integer.parseInt(st.nextToken());
39+
int dir = Integer.parseInt(st.nextToken());
40+
now = new Pos(nowX, nowY, dir);
41+
42+
g = new int[N][M];
43+
for(int i=0; i<N; i++){
44+
st = new StringTokenizer(br.readLine());
45+
for(int j=0; j<M; j++){
46+
g[i][j] = Integer.parseInt(st.nextToken());
47+
}
48+
}
49+
visited = new boolean[N][M];
50+
visited[now.x][now.y] = true;
51+
52+
// ์ž์œจ์ฃผํ–‰ ์‹œ์ž‘
53+
while(true){
54+
// ์ขŒํšŒ์ „
55+
Pos np = turnLeft(now.d);
56+
// 1๋ฒˆ
57+
if(g[np.x][np.y] == 0 && !visited[np.x][np.y]){
58+
go(np);
59+
} else {
60+
boolean isOk = false;
61+
for(int i=0; i<3; i++){
62+
np = turnLeft(np.d);
63+
if(g[np.x][np.y] == 0 && !visited[np.x][np.y]) {
64+
isOk = true;
65+
break;
66+
}
67+
}
68+
if(isOk){
69+
go(np);
70+
}
71+
// 3๋ฒˆ
72+
else{
73+
np = back(now.d);
74+
if(g[np.x][np.y] == 1){
75+
break;
76+
}
77+
go(np);
78+
}
79+
}
80+
}
81+
// for(int i=0; i<N; i++){
82+
// System.out.println(Arrays.toString(visited[i]));
83+
// }
84+
int ans = 0;
85+
for(int i=0; i<N; i++){
86+
for(int j=0; j<M; j++){
87+
if(visited[i][j]){
88+
ans++;
89+
}
90+
}
91+
}
92+
System.out.println(ans);
93+
}
94+
public static Pos turnLeft(int d){
95+
int left = (d + 3) % 4;
96+
int nx = now.x + dx[left];
97+
int ny = now.y + dy[left];
98+
return new Pos(nx, ny, left);
99+
}
100+
public static Pos back(int d){
101+
int bDir = (d + 2) % 4;
102+
int nx = now.x + dx[bDir];
103+
int ny = now.y + dy[bDir];
104+
return new Pos(nx, ny, d);
105+
}
106+
public static void go(Pos np){
107+
visited[np.x][np.y] = true;
108+
now.x = np.x;
109+
now.y = np.y;
110+
now.d = np.d;
111+
}
112+
}
113+
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package day0909;
2+
3+
import java.util.*;
4+
import java.io.*;
5+
public class JY_๋ถˆ์•ˆํ•œ_๋ฌด๋น™์›Œํฌ {
6+
7+
static int N, K;
8+
static Block[] urr;
9+
static Block[] brr;
10+
static class Block {
11+
int st;
12+
boolean visited;
13+
public Block(int st, boolean visited) {
14+
this.st = st;
15+
this.visited = visited;
16+
}
17+
@Override
18+
public String toString() {
19+
return "s:"+this.st+" "+this.visited;
20+
}
21+
}
22+
23+
public static void main(String[] args) throws IOException{
24+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
25+
StringTokenizer st = new StringTokenizer(br.readLine());
26+
27+
N = Integer.parseInt(st.nextToken());
28+
K = Integer.parseInt(st.nextToken());
29+
30+
urr = new Block[100];
31+
st = new StringTokenizer(br.readLine());
32+
for(int i=0; i<N; i++){
33+
urr[i] = new Block(Integer.parseInt(st.nextToken()), false);
34+
}
35+
brr = new Block[100];
36+
for(int i=0; i<N; i++){
37+
brr[i] = new Block(Integer.parseInt(st.nextToken()), false);
38+
}
39+
40+
// System.out.println(Arrays.toString(urr));
41+
// System.out.println(Arrays.toString(brr));
42+
43+
int test = 0;
44+
while(!done()) {
45+
game();
46+
test++;
47+
}
48+
49+
System.out.println(test);
50+
51+
}
52+
public static boolean done() {
53+
int fail = 0;
54+
for(int i=0; i<N; i++) {
55+
if(urr[i].st == 0) fail++;
56+
if(brr[i].st == 0) fail++;
57+
}
58+
return fail >= K;
59+
}
60+
public static void game() {
61+
// ๋ฌด๋น™์›Œํฌ ํšŒ์ „
62+
shift();
63+
64+
// ์‚ฌ๋žŒ ์ด๋™ + ์•ˆ์ •์„ฑ ์ฒ˜๋ฆฌ
65+
moveAll();
66+
67+
// ์‚ฌ๋žŒ ์ฆ๊ฐ€ + ์•ˆ์ •์„ฑ ์ฒ˜๋ฆฌ
68+
add();
69+
70+
// N๋ฒˆ์งธ ์นธ์— ์‚ฌ๋žŒ์žˆ์œผ๋ฉด ๋‚ด๋ฆผ
71+
if(urr[N-1].visited) {
72+
move(N-1);
73+
}
74+
}
75+
public static void shift() {
76+
Block tmp = urr[N-1];
77+
for(int i=N-1; i>= 1; i--) {
78+
urr[i] = urr[i-1];
79+
}
80+
urr[0] = brr[N-1];
81+
82+
for(int i=N-1; i>=1; i--) {
83+
brr[i] = brr[i-1];
84+
}
85+
brr[0] = tmp;
86+
}
87+
public static void add() {
88+
// ์•ˆ์ •์„ฑ 0์ด์ƒ, ์‹œ์ž‘์นธ์— ์‚ฌ๋žŒ ์—†๋Š” ๊ฒฝ์šฐ
89+
if(urr[0].st > 0 && !urr[0].visited) {
90+
// urr[0].st--;
91+
// urr[0].visited = true;
92+
urr[0] = new Block(urr[0].st-1, true);
93+
}
94+
}
95+
public static boolean canGo(int idx) {
96+
// N์ด์ƒ์ด๋ฉด ๋ฐ–์œผ๋กœ ๋‚˜๊ฐ
97+
if(idx == N) return true;
98+
99+
return urr[idx].st > 0 && !urr[idx].visited;
100+
}
101+
public static void move(int idx) {
102+
// idx ์œ„์น˜์˜ ์‚ฌ๋žŒ ์‚ฌ๋ผ์ง
103+
urr[idx] = new Block(urr[idx].st, false);
104+
105+
// ๋ฐ–์œผ๋กœ ๋‚˜๊ฐ€๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ฉด ๋‹ค์Œ ์นธ์— ์‚ฌ๋žŒ ์ถ”๊ฐ€
106+
if(idx + 1 < N) {
107+
urr[idx+1] = new Block(urr[idx+1].st - 1, true);
108+
}
109+
}
110+
public static void moveAll() {
111+
// ์‚ฌ๋žŒ์ด ์žˆ๊ณ , ๊ทธ ๋‹ค์Œ ์œ„์น˜๋กœ ์ด๋™ ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ
112+
for(int i=N-1; i>=0 ;i--) {
113+
if(urr[i].visited && canGo(i+1)) {
114+
move(i);
115+
}
116+
}
117+
}
118+
}

0 commit comments

Comments
(0)

AltStyle ใซใ‚ˆใฃใฆๅค‰ๆ›ใ•ใ‚ŒใŸใƒšใƒผใ‚ธ (->ใ‚ชใƒชใ‚ธใƒŠใƒซ) /