<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>10026 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/10026/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Wed, 22 Feb 2023 23:54:36 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://lycos7560.com/wp-content/uploads/2022/11/cropped-cropped-cropped-log-1-150x150-1-80x80.png</url>
	<title>10026 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>백준 10026번 (적록색약, C++, BFS) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10026%eb%b2%88-%ec%a0%81%eb%a1%9d%ec%83%89%ec%95%bd-c-bfs-baekjoon/5656/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10026%eb%b2%88-%ec%a0%81%eb%a1%9d%ec%83%89%ec%95%bd-c-bfs-baekjoon/5656/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 27 Jan 2023 10:57:34 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[10026]]></category>
		<category><![CDATA[10026번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 10026]]></category>
		<category><![CDATA[백준 10026번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[적록 색약]]></category>
		<category><![CDATA[적록색약]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5656</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 10026번 '적록색약' 문제에 대한 글입니다. BFS Search을 이용하여 해결하였습니다. (This is an article on the issue of 'red medicine' in BAEKJOON No. 10026. I solved it using BFS Search.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10026%eb%b2%88-%ec%a0%81%eb%a1%9d%ec%83%89%ec%95%bd-c-bfs-baekjoon/5656/">백준 10026번 (적록색약, C++, BFS) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">적록색약</h1>



<p class="has-medium-font-size wp-block-paragraph"><a href="https://www.acmicpc.net/problem/10026" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/10026</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">1 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">43852</td><td class="has-text-align-left" data-align="left">25157</td><td class="has-text-align-left" data-align="left">19376</td><td class="has-text-align-left" data-align="left">56.534%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size wp-block-paragraph">적록색약은 빨간색과 초록색의 차이를 거의 느끼지 못한다. </p>



<p class="has-medium-font-size wp-block-paragraph">따라서, 적록색약인 사람이 보는 그림은 아닌 사람이 보는 그림과는 좀 다를 수 있다.</p>



<p class="has-medium-font-size wp-block-paragraph">크기가 N×N인 그리드의 각 칸에 R(빨강), G(초록), B(파랑) 중 하나를 색칠한 그림이 있다. </p>



<p class="has-medium-font-size wp-block-paragraph">그림은 몇 개의 구역으로 나뉘어져 있는데, 구역은 같은 색으로 이루어져 있다. </p>



<p class="has-medium-font-size wp-block-paragraph">또, 같은 색상이 상하좌우로 인접해 있는 경우에 두 글자는 같은 구역에 속한다. </p>



<p class="has-medium-font-size wp-block-paragraph">(색상의 차이를 거의 느끼지 못하는 경우도 같은 색상이라 한다)</p>



<p class="has-medium-font-size wp-block-paragraph">예를 들어, 그림이 아래와 같은 경우에</p>



<div style="height:10px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">RRRBB
GGBBB
BBBRR
BBRRR
RRRRR</pre>



<div style="height:10px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:10px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">적록색약이 아닌 사람이 봤을 때 구역의 수는 총 4개이다. (빨강 2, 파랑 1, 초록 1) </p>



<p class="has-medium-font-size wp-block-paragraph">하지만, 적록색약인 사람은 구역을 3개 볼 수 있다. (빨강-초록 2, 파랑 1)</p>



<p class="has-medium-font-size wp-block-paragraph">그림이 입력으로 주어졌을 때, </p>



<p class="has-medium-font-size wp-block-paragraph">적록색약인 사람이 봤을 때와 아닌 사람이 봤을 때 구역의 수를 구하는 프로그램을 작성하시오.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size wp-block-paragraph">첫째 줄에 N이 주어진다. (1 ≤ N ≤ 100)</p>



<p class="has-medium-font-size wp-block-paragraph">둘째 줄부터 N개 줄에는 그림이 주어진다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size wp-block-paragraph">적록색약이 아닌 사람이 봤을 때의 구역의 개수와 적록색약인 사람이 봤을 때의 구역의 수를 공백으로 구분해 출력한다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5
RRRBB
GGBBB
BBBRR
BBRRR
RRRRR</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4 3</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<p class="wp-block-paragraph"><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a> > <a href="https://www.acmicpc.net/category/106" target="_blank" rel="noreferrer noopener">USA Computing Olympiad</a> > <a href="https://www.acmicpc.net/category/281" target="_blank" rel="noreferrer noopener">2013-2014 Season</a> > <a href="https://www.acmicpc.net/category/296" target="_blank" rel="noreferrer noopener">USACO March 2014 Contest</a> > <a href="https://www.acmicpc.net/category/detail/1243" target="_blank" rel="noreferrer noopener">Bronze</a> 3번</p>



<ul class="wp-block-list">
<li>문제를 번역한 사람: <a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>어색한 표현을 찾은 사람: <a href="https://www.acmicpc.net/user/corea" target="_blank" rel="noreferrer noopener">corea</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/7" target="_blank" rel="noreferrer noopener">그래프 이론</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/11" target="_blank" rel="noreferrer noopener">그래프 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/126" target="_blank" rel="noreferrer noopener">너비 우선 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/127" target="_blank" rel="noreferrer noopener">깊이 우선 탐색</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<p class="has-medium-font-size wp-block-paragraph">다른 BFS 문제들과 크게 차이가 나지 않는 문제</p>



<p class="has-medium-font-size wp-block-paragraph"><strong>적록 색약인 사람이 보는 맵과 일반인이 보는 맵을 따로 만들어서 BFS를 2번 해주었다.</strong></p>



<p class="has-medium-font-size wp-block-paragraph">탐색의 방법은 DFS도 가능할 듯</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">통과된 코드</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;queue>

using namespace std;

constexpr int MAX = 100;

queue&lt;pair&lt;int,int>> myPQ;

int N;

// 0:일반 1:적녹색약
int cnt[2];

pair&lt;int, int> temp;

string str[MAX];

char normalMap[MAX][MAX]; // 일반인이 보는 맵

char rgMap[MAX][MAX]; // 적녹색약이 보는 맵

bool mapCheck[MAX][MAX]; // BFS 방문 처리

// 탐색하는 방향 설정 =>  상, 하 ,좌 ,우
int dxdy[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };


void BFS(int x, int y, char map[MAX][MAX])
{
    myPQ.push(make_pair(x, y));
    mapCheck[x][y] = true;

    while (!myPQ.empty()) {

        temp = myPQ.front();
        myPQ.pop();

        int nowX, nowY;
        for (int i = 0; i &lt; 4; i++) {
            nowX = temp.first + dxdy[i][0];
            nowY = temp.second + dxdy[i][1];

            // 문제의 범위를 벗어나는 경우 => 넘어간다.
            if (nowX &lt; 0 || nowY &lt; 0 || nowX >= N || nowY >= N) continue;
            if (map[temp.first][temp.second] != map[nowX][nowY] || mapCheck[nowX][nowY] == true) continue;
  
            mapCheck[nowX][nowY] = true;
            myPQ.push(make_pair(nowX, nowY));
        }
    }

}

int main()
{
	cin >> N;

	for (int i = 0; i &lt; N; i++)	cin >> str[i];

	for (int i = 0; i &lt; N; i++) {
        for (int j = 0; j &lt; N; j++) {
            // 일반인이 보는 맵
            normalMap[i][j] = str[i][j];

            // 적록색약이 보는 맵
            if (str[i][j] == 'G') rgMap[i][j] = 'R';
            else rgMap[i][j] = str[i][j];

        }
	}

    // 일반인이 보는 맵 BFS
    for (int i = 0; i &lt; N; i++) {
        for (int j = 0; j &lt; N; j++) {
            if (mapCheck[i][j] == false) {
                BFS(i, j, normalMap);
                cnt[0]++;
            }
        }
    }

    // 방문처리 초기화
    for (int i = 0; i &lt; N; i++) {
        for (int j = 0; j &lt; N; j++) {
            mapCheck[i][j] = false;
        }
    }

    // 적록색약이 보는 맵 BFS
    for (int i = 0; i &lt; N; i++) {
        for (int j = 0; j &lt; N; j++) {
            if (mapCheck[i][j] == false) {
                BFS(i, j, rgMap);
                cnt[1]++;
            }
        }
    }

    // 결과 출력
    cout &lt;&lt; cnt[0] &lt;&lt; " " &lt;&lt; cnt[1];

	return 0;
}</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1035" height="104" src="https://lycos7560.com/wp-content/uploads/2023/01/image-26.png" alt="" class="wp-image-5657" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-26.png 1035w, https://lycos7560.com/wp-content/uploads/2023/01/image-26-300x30.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-26-768x77.png 768w" sizes="(max-width: 1035px) 100vw, 1035px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10026%eb%b2%88-%ec%a0%81%eb%a1%9d%ec%83%89%ec%95%bd-c-bfs-baekjoon/5656/">백준 10026번 (적록색약, C++, BFS) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10026%eb%b2%88-%ec%a0%81%eb%a1%9d%ec%83%89%ec%95%bd-c-bfs-baekjoon/5656/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
