티스토리 뷰
6. B - Minesweeper
코드
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
st = new StringTokenizer(br.readLine());
int h = Integer.parseInt(st.nextToken());
int w = Integer.parseInt(st.nextToken());
String[] strs = new String[h];
for (int i = 0; i < strs.length; i++) {
strs[i] = br.readLine();
}
int[][] board = new int[h][w];
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (strs[y].charAt(x) == '#') {
board[y][x] = -100;
for (int dy = -1; dy <= 1; dy++) {
for (int dx = -1; dx <= 1; dx++) {
int ny = y + dy;
int nx = x + dx;
if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
board[ny][nx]++;
}
}
}
}
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[0].length; j++) {
if (board[i][j] < 0) sb.append('#');
else sb.append(board[i][j]);
}
sb.append('\n');
}
bw.write(sb.toString());
bw.flush();
bw.close();
br.close();
}
}
7. B - Cut and Count
코드
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
int n = Integer.parseInt(br.readLine());
String str = br.readLine();
int ans = 0;
for (int i = 1; i < str.length(); i++) {
boolean[] a = new boolean[26];
for (int j = 0; j < i; j++) {
a[str.charAt(j) - 'a'] = true;
}
boolean[] b = new boolean[26];
for (int j = i; j < str.length(); j++) {
b[str.charAt(j) - 'a'] = true;
}
int cnt = 0;
for (int j = 0; j < 26; j++) {
if (a[j] && b[j]) cnt++;
}
ans = Math.max(ans, cnt);
}
bw.write(ans + "");
bw.flush();
bw.close();
br.close();
}
}
8. C - Colorful Leaderboard
풀이
최소를 구할 때 주의해야 한다. rating이 3200 미만인 인원이 한 명이라도 있는 경우 서로 다른 색깔의 수이고 없다면 rating이 3200 이상인 인원들의 색을 하나로 고정한 경우가 최소이다.
코드
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
int[] score = new int[]{400, 800, 1200, 1600, 2000, 2400, 2800, 3200};
int n = Integer.parseInt(br.readLine());
st = new StringTokenizer(br.readLine());
boolean[] color = new boolean[score.length];
int free = 0;
for (int i = 0; i < n; i++) {
int cur = Integer.parseInt(st.nextToken());
int idx = 0;
while (idx < score.length && score[idx] <= cur) idx++;
if (idx < score.length) color[idx] = true;
else free++;
}
int cnt = 0;
for (int i = 0; i < color.length; i++) {
if (color[i]) cnt++;
}
int min = Math.max(cnt, 1);
int max = cnt + free;
bw.write(min + " " + max);
bw.flush();
bw.close();
br.close();
}
}
9. B - Choose Integer
코드
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
HashSet<Integer> set = new HashSet<>();
int sum = a;
while (!set.contains(sum % b)) {
set.add(sum % b);
sum += a;
}
bw.write(set.contains(c) ? "YES" : "NO");
bw.flush();
bw.close();
br.close();
}
}
10. C - Together
코드
import java.io.*;
import java.util.*;
public class Main {
public static void add(HashMap<Integer, Integer> map, int n) {
map.putIfAbsent(n, 0);
map.replace(n, map.get(n) + 1);
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
int n = Integer.parseInt(br.readLine());
st = new StringTokenizer(br.readLine());
HashMap<Integer, Integer> map = new HashMap();
for (int i = 0; i < n; i++) {
int cur = Integer.parseInt(st.nextToken());
add(map, cur - 1);
add(map, cur);
add(map, cur + 1);
}
int ans = 0;
for (int x : map.values()) {
ans = Math.max(ans, x);
}
bw.write(ans + "");
bw.flush();
bw.close();
br.close();
}
}
'컴퓨터공학 > Problem Solving' 카테고리의 다른 글
Atcoder Boot camp Problems Medium 1 ~ 5 (0) | 2022.11.13 |
---|---|
[백준/BOJ] 1152 : 단어의 개수 (자바/Java) (0) | 2022.09.12 |
[백준/BOJ] 1008 : A/B (자바/Java) (0) | 2022.09.12 |
[백준/BOJ] 1001 :A-B (자바/Java) (0) | 2022.09.12 |
[백준/BOJ] 1000 : A+B (자바/Java) (0) | 2022.09.12 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- boj 2243
- 백준 16562
- boj 2336
- boj 9345
- 백준 10775
- 백준 14868
- boj 12713
- 백준 1106
- 터보소트
- 디지털 비디오 디스크
- 부트 캠프
- boj 3006
- 제로베이스 스쿨
- boj 14868
- 백준 1280
- boj 1280
- boj 1106
- Ugly Numbers
- 백준 2336
- 백준 12713
- 백준 10473
- 백준 3006
- 백준 2243
- 백준 9345
- boj 10473
- boj 10775
- 사탕상자
- 인간 대포
- 제로베이스 백엔드 스쿨
- boj 16562
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함