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
- 누적 합
- Team Fortress 2
- 백트래킹
- 문자열
- BFS
- XR Interaction Toolkit
- 구현
- 스택
- 정렬
- 시뮬레이션
- 다이나믹 프로그래밍
- 브루트포스
- c++
- 투 포인터
- 백준
- Unreal Engine 5
- DFS
- 유니온 파인드
- VR
- 알고리즘
- 트리
- 수학
- 다익스트라
- 우선순위 큐
- 그래프
- 그리디 알고리즘
- 자료구조
- 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 |