cyphen156
백준-정렬 좌표 압축 본문
1차원 좌표가 주어진다.
f(x1) = countIF(x1 > Except Equal val( x2 || x3 || xn-1))
제약사항
- 0 < N ≤ 1,000,000
- -10**9 <= Input <= 10**9
주의 사항
없다.
CPP풀이
좌표 압축_18870.cpp
/**
* 백준 좌표 압축_18870
* 1차원 좌표가 주어진다.
* f(x1) = countIF(x1 > Except Equal val( x2 || x3 || xn-1))
*
* 제한사항
*****************************************
* 0 < N ≤ 1,000,000 *
* -10**9 <= Input <= 10**9 *
*****************************************
*
*
*
* 주의
* 없다.
*
* 풀이시간 30분
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int BSearch(int search, vector<int>& copyVector)
{
int left = 0;
int right = size(copyVector) - 1;
while (left <= right)
{
int mid = (left + right) / 2;
if (search == copyVector[mid])
{
return mid;
}
else if (search > copyVector[mid])
{
left = mid + 1;
}
else
{
right = mid - 1;
}
}
return 0;
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
vector<int> inputs;
for (int i = 0; i < N; ++i)
{
int input;
cin >> input;
inputs.push_back(input);
}
vector<int> copyVector(inputs);
sort(copyVector.begin(), copyVector.end());
copyVector.erase(unique(copyVector.begin(),copyVector.end()),copyVector.end());
for (int i = 0; i < size(inputs); ++i)
{
cout << BSearch(inputs[i], copyVector)<< ' ';
}
cout << '\n';
return 0;
}
모든 예제 코드의 소스파일은 제 개인 깃허브 레포지토리 에 있습니다.
Workspace/알고리듬 풀이 at main · cyphen156/Workspace
Studying . Contribute to cyphen156/Workspace development by creating an account on GitHub.
github.com
'컴퓨터공학 > 알고리듬 풀이' 카테고리의 다른 글
백준-집합과 맵 14425 문자열 집합 (0) | 2025.05.07 |
---|---|
백준-집합과 맵 10815 숫자 카드 (0) | 2025.04.30 |
백준-정렬 10814 나이순 정렬 (0) | 2025.04.29 |
백준-정렬 1181 단어 정렬 (0) | 2025.04.28 |
백준-정렬 11651 좌표 정렬하기 2 (0) | 2025.04.28 |