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
- XR Interaction Toolkit
- BFS
- 다익스트라
- 백준
- 누적 합
- 구현
- c++
- 유니티
- 브루트포스
- 스택
- Team Fortress 2
- 수학
- 알고리즘
- 유니온 파인드
- 문자열
- 다이나믹 프로그래밍
- 재귀
- VR
- 자료구조
- 시뮬레이션
- 투 포인터
- DFS
- Unreal Engine 5
- 그리디 알고리즘
- 백트래킹
- ue5
- 그래프
- 트리
- 우선순위 큐
- 정렬
Archives
- Today
- Total
1일1알
백준 2872번 우리집엔 도서관이 있어 C++ 본문

전체 책의 갯수에서 이미 정렬되어있는 책의 갯수를 빼면 된다.
예를 들어 책이 6권 있고, 4 1 5 2 6 3 이런 식으로 되어 있다면, 4, 5, 6은 이미 정렬된 상태이기 때문에 1, 2, 3을 빼서 위에 놓으면 된다.
#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 <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
int n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
int cnt = 0;
int target = n;
for (int i = n; i > 0; i--) {
if (v[i] == target) {
cnt++;
target--;
}
}
cout << n - cnt;
};
'알고리즘' 카테고리의 다른 글
백준 1092번 배 C++ (0) | 2022.01.26 |
---|---|
백준 1474번 밑 줄 C++ (0) | 2022.01.25 |
백준 2891번 카약과 강풍 C++ (0) | 2022.01.23 |
백준 5747 Odd or Even C++ (0) | 2022.01.23 |
백준 2636번 치즈 C++ (0) | 2022.01.22 |