Skip to content

[유병규-15주차 알고리즘 스터디] #72

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions 유병규_15주차/[BOJ-18119] 단어 암기.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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));

StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());

//단어 저장
List<Integer> words = new ArrayList<>();
for(int i=0; i<n; i++) {
String input = br.readLine();
int word = 0;
for(char c : input.toCharArray()) {
int offset = c - 'a';
int target = (1 << offset);
word = word | target;
}
words.add(word);
}

//현재 기억하는 알파벳 정보
int current = (1 << ('z'-'a') + 1) - 1;

StringBuilder sb = new StringBuilder();
for(int i=0; i<m; i++) {
String[] input = br.readLine().split(" ");

int offset = input[1].charAt(0) - 'a';
int target = (1 << offset);

//1이면 해당 알파벳을 잊어버림
if(input[0].equals("1")) current = current ^ target;
//0이면 다시 기억함
else current = current | target;

//모든 단어와 비교하여 해당 단어의 알파벳을 모두 기억하면 +1
int count = 0;
for(int word : words) {
if(word == (word & current)) count++;
}
sb.append(count).append("\n");
}

System.out.println(sb.toString().trim());
}
}
37 changes: 37 additions & 0 deletions 유병규_15주차/[BOJ-1911] 흙길 보수하기.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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));

StringTokenizer st = new StringTokenizer(br.readLine());

int n = Integer.parseInt(st.nextToken());
int l = Integer.parseInt(st.nextToken());

int[][] water = new int[n][2];
for(int i=0; i<n; i++) {
st = new StringTokenizer(br.readLine());
water[i][0] = Integer.parseInt(st.nextToken());
water[i][1] = Integer.parseInt(st.nextToken());
}

Arrays.sort(water, (o1, o2) -> Integer.compare(o1[0], o2[0]));

int result = 0;
int pre = 0;
for(int i=0; i<n; i++) {
//널빤지의 끝 위치와 웅덩이의 시작 위치 중 더 큰 값으로 설정
pre = Math.max(pre, water[i][0]);
//하나씩 놓기
while(pre < water[i][1]) {
result++;
pre += l;
}
}

System.out.println(result);
}
}
49 changes: 49 additions & 0 deletions 유병규_15주차/[BOJ-3020] 개똥벌레.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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));

StringTokenizer st = new StringTokenizer(br.readLine());

//입력 값 저장
int n = Integer.parseInt(st.nextToken());
int h = Integer.parseInt(st.nextToken());

int[] number = new int[n];
for(int i=0; i<n; i++) {
number[i] = Integer.parseInt(br.readLine());
}

//석순의 변화량을 체크
int[] count = new int[h];
for(int i=0; i<n; i+=2) {
count[0]++;
count[number[i]]--;
}

//종유석의 변화량을 체크
for(int i=1; i<n; i+=2) {
count[h-number[i]]++;
}

//누적합 배열 세팅
int[] sum = new int[h];
sum[0] = count[0];
for(int i=1; i<h; i++) {
sum[i] = sum[i-1]+count[i];
}

//가장 작은 값과 그 개수 구하기
Arrays.sort(sum);
int result = 1;
for(int i=1; i<h; i++) {
if(sum[0] != sum[i]) break;
result++;
}

System.out.println(sum[0]+" "+result);
}
}