일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- spring websocket nginx 설정
- presigned url
- S3
- validation
- fastapi
- 자바 orm
- OpenAI API
- spring boot
- oauth2.0
- 소셜 로그인
- 예외 처리
- 구글 로그인
- 개발 프로젝트
- 이미지 업로드
- wss 연결 실패
- CustomException
- 패러다임 불일치
- Flask
- 관점 지향 프로그래밍
- GoormIDE
- AWS
- @Valid
- springboot
- ec2 nginx websocket reverse proxy
- 백준 10815 # 백준 Java
- jwt
- session
- 도메인 주도 개발
- logout
- 스프링부트
Archives
- Today
- Total
개발세발은 안되요
[C++] 백준 20365 : 블로그2 본문
문제
https://www.acmicpc.net/problem/20365
풀이
- 빨간색 블록과 파란색 블록 중 더 많이 등장하는 블록의 색을 구한다.
- 우선 1에서 구한 색으로 전체를 칠한다.
- 더 적게 등장한 색의 블록 각각 칠한다.
이를 식으로 표현하면 다음과 같다.
ans = min(red_block , blue_block) + a
코드
#include <iostream>
#include <string>
using namespace std;
string s;
int n,R_cnt, B_cnt;
int ans;
int main()
{
cin >> n;
cin >> s;
//블록 개수 구하기
char cur_block = s[0];
if(cur_block == 'R') R_cnt++;
else B_cnt++;
for(int i=1; i<s.length(); i++){
if(s[i] != cur_block){
cur_block = s[i];
if(cur_block == 'R') R_cnt++;
else B_cnt++;
}
}
if(R_cnt > B_cnt) ans = B_cnt + 1;
else ans = R_cnt + 1;
cout << ans << "\n";
return 0;
}
'알고리즘 > 백준' 카테고리의 다른 글
[C++] 백준 1041 : 주사위 (0) | 2025.05.21 |
---|---|
[C++] 백준 21758 : 꿀 따기 (0) | 2025.05.15 |
[C++] 백준 21315: 카드 섞기 (0) | 2025.05.04 |
[C++] 백준 2469 : 사다리 타기 (0) | 2025.05.01 |
[C++] 백준 1874 : 스택 수열 (0) | 2025.04.30 |