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 |
Tags
- 문자열
- 유니티
- VR
- 투 포인터
- 누적 합
- Team Fortress 2
- 다익스트라
- 백트래킹
- 우선순위 큐
- 트리
- 백준
- 시뮬레이션
- 알고리즘
- 정렬
- DFS
- 브루트포스
- Unreal Engine 5
- 수학
- c++
- 그래프
- XR Interaction Toolkit
- 재귀
- 자료구조
- 그리디 알고리즘
- 구현
- 스택
- ue5
- BFS
- 유니온 파인드
- 다이나믹 프로그래밍
Archives
- Today
- Total
1일1알
백준 19637번 IF문 좀 대신 써줘 C++ 본문
https://www.acmicpc.net/problem/19637
19637번: IF문 좀 대신 써줘
첫 번째 줄에는 칭호의 개수 N (1 ≤ N ≤ 105)과 칭호를 출력해야 하는 캐릭터들의 개수 M (1 ≤ M ≤ 105)이 빈칸을 사이에 두고 주어진다. (1 ≤ N, M ≤ 105) 두 번째 줄부터 N개의 줄에 각 칭
www.acmicpc.net
처음에 범위를 안보고 풀다가 시간초과가 났다.
이분탐색을 해결하였다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n, m;
vector<int> v;
map<int, string> mp;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
for (int i = 0; i < n; i++) {
string str;
int power;
cin >> str >> power;
v.push_back(power);
mp.insert({ i,str });
}
for (int i = 0; i < m; i++) {
int power;
cin >> power;
int idx = lower_bound(v.begin(), v.end(), power) - v.begin();
cout << mp[idx] << "\n";
}
}
'알고리즘' 카테고리의 다른 글
백준 21278번 호석이 두 마리 치킨 C++ (1) | 2023.06.08 |
---|---|
백준 3182번 한동이는 공부가 하기 싫어! C++ (0) | 2023.06.07 |
백준 18404번 현명한 나이트 C++ (0) | 2023.06.04 |
백준 1986번 체스 C++ (0) | 2023.06.01 |
백준 15664번 N과 M(10) C++ (0) | 2023.05.30 |