🌞Algorithm/🔥Baekjoon

[Baekjoon] 17599_Bags

뿌야._. 2025. 2. 28. 17:13
문제(출처: https://www.acmicpc.net/problem/17599)

< Bags >

 

문제 풀이 

 

HashSet을 사용하여 독성 폐기물을 안전하게 수집하는 데 필요한 최소 쓰레기봉투 수를 구한다.

 

my solution (Java)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;

public class _17599_ { // Bags

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		int n = Integer.parseInt(bf.readLine());

		HashSet<Integer> set = new HashSet<>();
		st = new StringTokenizer(bf.readLine());
		for (int i = 0; i < n; i++) {
			set.add(Integer.parseInt(st.nextToken()));
		}

		System.out.println(set.size());
	}
}
변수)
n : 독성 폐기물 수
set : 독성 폐기물 종류

 

독성 폐기물 수 n을 입력받는다. n개만큼 독성 폐기물의 식별자를 입력받아 HashSet에 저장한다. 최종 HashSet의 크기를 출력한다.



 

'🌞Algorithm > 🔥Baekjoon' 카테고리의 다른 글

[Baekjoon] 12723_Minimum Scalar Product (Small)  (0) 2025.03.11
[Baekjoon] 24155_得点 (Score)  (0) 2025.03.10
[Baekjoon] 5092_Air Old Zeeland  (0) 2025.02.27
[Baekjoon] 8975_PJESMA  (0) 2025.02.26
[Baekjoon] 14534_String Permutation  (0) 2025.02.25