https://www.acmicpc.net/problem/20365

 

20365번: 블로그2

neighbor 블로그를 운영하는 일우는 매일 아침 풀고 싶은 문제를 미리 정해놓고 글을 올린다. 그리고 매일 밤 각각의 문제에 대하여, 해결한 경우 파란색, 해결하지 못한 경우 빨간색으로 칠한

www.acmicpc.net

그리드 문제는 진짜 후 어렵네요.

한번에 통과를 못하네여 

#include <iostream>
#include <vector>
#include <queue>
#include<string>
#include<algorithm>
#include<cmath>
#include<unordered_map>
#include<map>
#include<stack>
using namespace std;

struct Point {
	int i, j, t, cnt;
	char c;
};

void Prints(vector<vector<int>>maps, int n, int m) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << maps[i][j];
		}
		cout << endl;
	}
	cout << endl;
}

void Prints(vector<vector<bool>>maps, int n, int m) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << maps[i][j];
		}
		cout << endl;
	}
	cout << endl;
}
void Prints(vector<vector<char>>maps, int n, int m) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << maps[i][j];
		}
		cout << endl;
	}
	cout << endl;
}
void Prints(vector<vector<vector<char>>>maps, int n, int m, int k) {
	for (int t = 0; t < k; t++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << maps[t][i][j];
			}
			cout << endl;
		}
		cout << endl;
	}
	cout << endl;
}

void Prints(vector<vector<vector<bool>>>maps, int n, int m, int k) {
	for (int t = 0; t < k; t++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << maps[t][i][j];
			}
			cout << endl;
		}
		cout << endl;
	}
	cout << endl;
}
void Prints(string str, int n) {
	for (int i = 0; i < n; i++) {
		cout << str[i] << ",";
	}
	cout << endl;
}

struct Data {
	int score;
	int index;
};

struct Word {
	std::string word;
	int count;
};

int main() {
	int n;
	string str;
	cin >> n;
	cin >> str;
	
	int redCount = 0;
	int blueCount = 0;
	int allCount = n;
	bool bBlue = false;
	int colorBlueCount = 0;
	int colorRedCount = 0;
	int colorCount = 0;
	bool bRed = false;
	for (int i = 0; i < n; i++)
	{
		if (str[i] == 'B'&&bBlue==false) {
			bBlue = true;
			bRed = false;
			colorBlueCount++;

		}
		else if (str[i] == 'R'&&bRed == false) {
			bRed = true;
			bBlue = false;
			colorRedCount++;
		}
		
		if (str[i] == 'B') {
			blueCount++;
		}
	}
	//cout << colorBlueCount<<",";
	//cout << colorRedCount;
	colorCount = colorBlueCount + colorRedCount;
	int cnt = 0;
	if (colorBlueCount <= colorRedCount) {
		cnt = 1 + colorBlueCount;
	}
	else if (colorBlueCount > colorRedCount) {
		cnt = 1 + colorRedCount;
	}


	if (colorCount < cnt) {
		cout << colorCount;
	}
	else {
		cout << cnt;
	}
	
	return 0;
}

'알고리즘 공부' 카테고리의 다른 글

백준 점프왕 쩰리 (Small)  (0) 2023.07.23
백준 에너지 드링크  (0) 2023.07.23
백준 바닥 장식  (0) 2023.07.23
백준 햄버거 분배  (0) 2023.07.23
백준 섬의개수  (0) 2023.07.23

+ Recent posts