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
- Zynq
- UNIX
- Vivado
- chip2chip
- boj
- baekjoon
- 리눅스
- AMBA BUS
- C++
- verilog
- 정처기
- java
- hdl
- Beakjoon
- 백준
- 실기
- vitis
- linux
- axi
- HDLBits
- 자격증
- 코딩테스트
- amba
- verilog HDL
- Bus
- Backjoon
- 정보처리기사
- SQL
- FPGA
- Xilinx
Archives
- Today
- Total
Hueestory
[1377] 버블 소트 (C++) 본문
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n; cin >> n;
vector<pair<int, int>> A(n);
vector<int> result(n);
for (int i = 0; i < n; i++) {
cin >> A[i].first;
A[i].second = i;
}
sort(A.begin(), A.end());
for (int i = 0; i < n; i++) {
result[i] = A[i].second - i;
}
sort(result.begin(), result.end());
cout << result[n - 1] + 1 << endl;
return 0;
}
1. 해당 문제에서 구하려는 것은 '몇 번째 수행에서 버블 정렬이 완료되는가'
2. 큰 수는 한 번의 버블 정렬 중 여러번 이동 할 수 있지만, 작은 수는 한 번의 버블 정렬 중 한번만 이동한다
=> 좌측으로 이동한 값 중 '가장 많이 이동한 횟수+1'를 구하는 것(원본도 포함해야 하므로 +1)
3. pair vector를 사용해 first에는 값, second에는 index를 정리
4. 정렬이 완료된 vector A의 second(index)값에 +1을 한 값을 result라는 vector에 정리
5. result를 sort하고 가장 큰 값(result[n-1] 항)에 +1 한 값을 출력
'PS(중단) > BOJ' 카테고리의 다른 글
[11399] ATM (C++) (0) | 2024.04.24 |
---|---|
[1427] 소트인사이드 (C++) (0) | 2024.04.24 |
[2750] 수 정렬하기 (C++) (0) | 2024.04.23 |
[11286] 절댓값 힙 (C++) (0) | 2024.04.22 |
[2164] 카드2 (C++) (0) | 2024.04.22 |
Comments