Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 29 | 30 | 31 |
Tags
- 에라토스테네스의 체
- 스택
- 그리디
- 위상정렬
- 후니의 쉽게 쓴 시스코 네트워킹
- mst
- 동적계획법
- 플로이드-와샬
- 수학
- dfs
- 세그먼트 트리
- java
- 투 포인터
- 백준
- 백트래킹
- Kotlin
- Effective Java
- 완전탐색
- swea
- CS
- BFS
- JUnit 5
- 문자열
- 구현
- 이분탐색
- 프로그래머스
- 시뮬레이션
- 알고리즘
- Network
- 유니온 파인드
Archives
반갑습니다!
[백준] 2776 암기왕 본문
풀이
문제 분류를 보면 이분 탐색을 의도한 것 같지만, HashSet을 사용해서 해결했다. C++에서는 HashSet이 unordered_set이므로 해당 STL을 사용해서 구현했다.
코드
#include <iostream>
#include <unordered_set>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
int n, m;
unordered_set<int> s;
while (t--) {
cin >> n;
s.clear();
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
s.insert(tmp);
}
cin >> m;
for (int i = 0; i < m; i++) {
int tmp;
cin >> tmp;
if (s.find(tmp) != s.end()) cout << "1\n";
else cout << "0\n";
}
}
return 0;
}'알고리즘 문제 풀이' 카테고리의 다른 글
| [백준] 6236 용돈 관리 (0) | 2020.09.11 |
|---|---|
| [백준] 3079 입국심사 (0) | 2020.09.11 |
| [백준] 2343 기타 레슨 (0) | 2020.09.11 |
| [백준] 12015 가장 긴 증가하는 부분 수열 2 (0) | 2020.09.11 |
| [백준] 1072 게임 (0) | 2020.09.11 |