Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 클라우드
- 로드밸런서
- 백트래킹
- gcp
- 개발자
- 스프링부트
- Spring Boot
- 오일러프로젝트
- 스프링
- JPA
- VPC
- DFS
- Kafka
- aws
- 클라우드 컴퓨팅
- 쿠버네티스
- 코드업
- 카프카
- springboot
- 백준
- Apache Kafka
- 월미도
- Spring
- 알고리즘
- Spring Data JPA
- Elasticsearch
- 프로그래밍문제
- 스프링 부트
- Docker
- 자료구조
Archives
- Today
- Total
GW LABS
[Backjoon] 좌표 압축 본문
정렬을 이용한 문제이다. 좌표들을 정렬하고 나서 원래 갖고 있던 인덱스를 통해 조건에 맞는 값을 출력하면 되는 문제였는데 set을 이용해서 자동으로 입력값들을 정렬하는 방식으로 접근했다. 다른 풀이법으로는 이진탐색을 이용해서 풀이하는 방법이 있었다.
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int count;
cin >> count;
set<int> cord_set;
int* cords = new int[count];
for (int idx = 0; idx < count; ++idx) {
int tmp;
scanf("%d", &tmp);
cords[idx] = tmp;
cord_set.insert(tmp);
}
map<int,int> cord_table;
set<int>::iterator iter = cord_set.begin();
for (int i = 0; i < cord_set.size(); ++i) {
cord_table[*iter] = i;
advance(iter, 1);
}
for (int i = 0; i < count; ++i) {
cout << cord_table[cords[i]] << " ";
}
cout << endl;
return 0;
}
'Algorithm & DataStructure > Problems' 카테고리의 다른 글
[Backjoon] 11586번 지영 공주님의 마법 거울 (0) | 2021.10.21 |
---|---|
[Backjoon] 순열 사이클 (0) | 2021.07.03 |
[Backjoon] 희주의 수학시험 (0) | 2021.06.24 |
[Backjoon] 동혁 피자 (0) | 2021.06.06 |
[Backjoon] 케빈 베이컨의 6단계 법칙 (0) | 2021.05.15 |
Comments