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 |
Tags
- 정렬
- 구현
- 우선순위 큐
- 그리디 알고리즘
- 브루트포스
- 투 포인터
- 다익스트라
- XR Interaction Toolkit
- 수학
- 유니온 파인드
- ue5
- 그래프
- c++
- 유니티
- 트리
- DFS
- 알고리즘
- 시뮬레이션
- 다이나믹 프로그래밍
- Team Fortress 2
- 백트래킹
- 재귀
- VR
- 누적 합
- 백준
- 자료구조
- 스택
- BFS
- 문자열
- Unreal Engine 5
Archives
- Today
- Total
1일1알
백준 20365번 블로그2 C++ 본문
https://www.acmicpc.net/problem/20365
B를 먼저 쭉 칠해놓은 경우와 R을 먼저 쭉 칠해놓은 경우를 비교해서 작은 값을 구한다.
#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 <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n;
string str;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
cin >> str;
int ans = n;
int ans1 = 1;
for (int i = 0; i < n;) {
if (str[i] == 'B') {
i++;
continue;
}
ans1++;
while (true) {
if (i >= n) break;
if (str[i] == 'B') break;
i++;
}
}
ans = min(ans, ans1);
int ans2 = 1;
for (int i = 0; i < n;) {
if (str[i] == 'R') {
i++;
continue;
}
ans2++;
while (true) {
if (i >= n) break;
if (str[i] == 'R') break;
i++;
}
}
ans = min(ans, ans2);
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 1986번 체스 C++ (0) | 2023.06.01 |
---|---|
백준 15664번 N과 M(10) C++ (0) | 2023.05.30 |
백준 10972번 다음 순열 C++ (0) | 2023.05.28 |
백준 19942번 다이어트 C++ (0) | 2023.05.27 |
백준 14675번 단절점과 단절선 C++ (0) | 2023.05.26 |