<?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>시뮬레이션 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/%EC%8B%9C%EB%AE%AC%EB%A0%88%EC%9D%B4%EC%85%98/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Mon, 10 Mar 2025 02:43:44 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://lycos7560.com/wp-content/uploads/2022/11/cropped-cropped-cropped-log-1-150x150-1-80x80.png</url>
	<title>시뮬레이션 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>백준 10813번 (공 바꾸기, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-10813%eb%b2%88-%ea%b3%b5-%eb%b0%94%ea%be%b8%ea%b8%b0-c-baekjoon/39908/</link>
					<comments>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-10813%eb%b2%88-%ea%b3%b5-%eb%b0%94%ea%be%b8%ea%b8%b0-c-baekjoon/39908/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 28 Feb 2025 02:32:58 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[10813]]></category>
		<category><![CDATA[10813번]]></category>
		<category><![CDATA[Baekjoon]]></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[백준 10813]]></category>
		<category><![CDATA[백준 10813번]]></category>
		<category><![CDATA[시뮬레이션]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=39908</guid>

					<description><![CDATA[<p>공 바꾸기 https://www.acmicpc.net/problem/10813 시간 제한 메모리 제한 제출 정답 맞힌 사람 정답 비율 1 초 256 MB 90321 56671 50445 63.108% 문제 도현이는 바구니를 총 N개 가지고 있고, 각각의 바구니에는 1번부터 N번까지 번호가 매겨져 있다. 바구니에는 공이 1개씩 들어있고, 처음에는 바구니에 적혀있는 번호와 같은 번호가 적힌 공이 들어있다. 도현이는 앞으로 M번 공을 바꾸려고 한다. 도현이는 [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-10813%eb%b2%88-%ea%b3%b5-%eb%b0%94%ea%be%b8%ea%b8%b0-c-baekjoon/39908/">백준 10813번 (공 바꾸기, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">공 바꾸기 <img decoding="async" width="35" height="45" class="wp-image-37920" style="width: 35px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Bronze_2.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Bronze_2.jpg 1250w, https://lycos7560.com/wp-content/uploads/2024/03/Bronze_2-234x300.jpg 234w, https://lycos7560.com/wp-content/uploads/2024/03/Bronze_2-768x983.jpg 768w, https://lycos7560.com/wp-content/uploads/2024/03/Bronze_2-1200x1536.jpg 1200w" sizes="(max-width: 35px) 100vw, 35px" /></h2>



<p><a href="https://www.acmicpc.net/problem/10813" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/10813</a></p>



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



<figure 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">256 MB</td><td class="has-text-align-left" data-align="left">90321</td><td class="has-text-align-left" data-align="left">56671</td><td class="has-text-align-left" data-align="left">50445</td><td class="has-text-align-left" data-align="left">63.108%</td></tr></tbody></table></figure>



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



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



<p>도현이는 바구니를 총 N개 가지고 있고, 각각의 바구니에는 1번부터 N번까지 번호가 매겨져 있다. </p>



<p>바구니에는 공이 1개씩 들어있고, 처음에는 바구니에 적혀있는 번호와 같은 번호가 적힌 공이 들어있다.</p>



<p>도현이는 앞으로 M번 공을 바꾸려고 한다. 도현이는 공을 바꿀 바구니 2개를 선택하고, 두 바구니에 들어있는 공을 서로 교환한다.</p>



<p>공을 어떻게 바꿀지가 주어졌을 때, M번 공을 바꾼 이후에 각 바구니에 어떤 공이 들어있는지 구하는 프로그램을 작성하시오.</p>



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



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



<p>첫째 줄에 N (1 ≤ N ≤ 100)과 M (1 ≤ M ≤ 100)이 주어진다.</p>



<p>둘째 줄부터 M개의 줄에 걸쳐서 공을 교환할 방법이 주어진다. </p>



<p>각 방법은 두 정수 i j로 이루어져 있으며, i번 바구니와 j번 바구니에 들어있는 공을 교환한다는 뜻이다. (1 ≤ i ≤ j ≤ N)</p>



<p>도현이는 입력으로 주어진 순서대로 공을 교환한다.</p>



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



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



<p>1번 바구니부터 N번 바구니에 들어있는 공의 번호를 공백으로 구분해 출력한다.</p>



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



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



<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 4
1 2
3 4
1 4
2 2</pre>



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



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



<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="">3 1 4 2 5</pre>



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



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



<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/onjo0127" target="_blank" rel="noreferrer noopener">onjo0127</a></li>
</ul>



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



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



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/102" target="_blank" rel="noreferrer noopener">구현</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/141" 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)"/>



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



<p>단순한 구현 문제</p>



<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>

using namespace std;

int N, M;
int Arr[101] = { 0 };

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

	cin >> N >> M;

    for (int i = 1; i &lt;= N; i++)
        Arr[i] = i;

	int t1, t2;

    for (int i = 0; i &lt; M; i++) {
        cin >> t1 >> t2;
		swap(Arr[t1], Arr[t2]);
    }

    for (int i = 1; i &lt;= N; i++)
		cout &lt;&lt; Arr[i] &lt;&lt; " ";

    return 0;
}
</pre>



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



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="965" height="82" src="https://lycos7560.com/wp-content/uploads/2025/03/image.png" alt="" class="wp-image-39909" srcset="https://lycos7560.com/wp-content/uploads/2025/03/image.png 965w, https://lycos7560.com/wp-content/uploads/2025/03/image-300x25.png 300w, https://lycos7560.com/wp-content/uploads/2025/03/image-768x65.png 768w" sizes="(max-width: 965px) 100vw, 965px" /></figure>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-10813%eb%b2%88-%ea%b3%b5-%eb%b0%94%ea%be%b8%ea%b8%b0-c-baekjoon/39908/">백준 10813번 (공 바꾸기, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-10813%eb%b2%88-%ea%b3%b5-%eb%b0%94%ea%be%b8%ea%b8%b0-c-baekjoon/39908/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2636번 (치즈, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-2636%eb%b2%88-%ec%b9%98%ec%a6%88-c-baekjoon/36604/</link>
					<comments>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-2636%eb%b2%88-%ec%b9%98%ec%a6%88-c-baekjoon/36604/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sat, 26 Aug 2023 02:52:29 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2636]]></category>
		<category><![CDATA[2636번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Gold]]></category>
		<category><![CDATA[Gold4]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[골드]]></category>
		<category><![CDATA[골드4]]></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[너비 우선 탐색]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 2636]]></category>
		<category><![CDATA[백준 2636번]]></category>
		<category><![CDATA[시뮬레이션]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[치즈]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36604</guid>

					<description><![CDATA[<p>백준 2636번 '치즈' 문제에 대한 글입니다. BFS 알고리즘을 이용하여 해결하였습니다.(This article is about the question of "Cheese" in Baekjoon Number 2636. It was solved using the BFS algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-2636%eb%b2%88-%ec%b9%98%ec%a6%88-c-baekjoon/36604/">백준 2636번 (치즈, C++) [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>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-75779d84      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#치즈" class="uagb-toc-link__trigger">치즈</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ul></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">치즈 <img decoding="async" width="30" height="38" class="wp-image-37904" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Gold_4.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Gold_4.jpg 400w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_4-234x300.jpg 234w" sizes="(max-width: 30px) 100vw, 30px" /></h1>



<p><a href="https://www.acmicpc.net/problem/2636" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/2636</a></p>



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



<figure 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">25672</td><td class="has-text-align-left" data-align="left">14240</td><td class="has-text-align-left" data-align="left">10335</td><td class="has-text-align-left" data-align="left">54.602%</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p>아래 &lt;그림 1&gt;과 같이 정사각형 칸들로 이루어진 사각형 모양의 판이 있고, </p>



<p>그 위에 얇은 치즈(회색으로 표시된 부분)가 놓여 있다. </p>



<p>판의 가장자리(&lt;그림 1&gt;에서 네모 칸에 X친 부분)에는 치즈가 놓여 있지 않으며 치즈에는 하나 이상의 구멍이 있을 수 있다.</p>



<p>이 치즈를 공기 중에 놓으면 녹게 되는데 공기와 접촉된 칸은 한 시간이 지나면 녹아 없어진다. </p>



<p>치즈의 구멍 속에는 공기가 없지만 구멍을 둘러싼 치즈가 녹아서 구멍이 열리면 구멍 속으로 공기가 들어가게 된다. </p>



<p>&lt;그림 1&gt;의 경우, 치즈의 구멍을 둘러싼 치즈는 녹지 않고 ‘c’로 표시된 부분만 한 시간 후에 녹아 없어져서 &lt;그림 2&gt;와 같이 된다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="379" height="408" src="https://lycos7560.com/wp-content/uploads/2023/08/image-25.png" alt="" class="wp-image-36609" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-25.png 379w, https://lycos7560.com/wp-content/uploads/2023/08/image-25-279x300.png 279w" sizes="(max-width: 379px) 100vw, 379px" /></figure>



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



<p>다시 한 시간 후에는 &lt;그림 2&gt;에서 ‘c’로 표시된 부분이 녹아 없어져서 &lt;그림 3&gt;과 같이 된다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="371" height="860" src="https://lycos7560.com/wp-content/uploads/2023/08/image-26.png" alt="" class="wp-image-36610" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-26.png 371w, https://lycos7560.com/wp-content/uploads/2023/08/image-26-129x300.png 129w" sizes="(max-width: 371px) 100vw, 371px" /></figure>



<p>&lt;그림 3&gt;은 원래 치즈의 두 시간 후 모양을 나타내고 있으며, </p>



<p>남은 조각들은 한 시간이 더 지나면 모두&nbsp;녹아 없어진다. </p>



<p>그러므로 처음 치즈가 모두 녹아 없어지는 데는 세 시간이 걸린다. </p>



<p>&lt;그림 3&gt;과 같이 치즈가 녹는 과정에서 여러 조각으로 나누어 질 수도 있다.</p>



<p>입력으로 사각형 모양의 판의 크기와 한 조각의 치즈가 판 위에 주어졌을 때, </p>



<p><strong>공기 중에서 치즈가 모두 녹아 없어지는 데 걸리는 시간과 </strong></p>



<p><strong>모두 녹기 한 시간 전에 남아있는 치즈조각이 놓여 있는 칸의 개수를 구하는 프로그램을 작성하시오.</strong></p>



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



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p>첫째 줄에는 사각형 모양 판의 세로와 가로의 길이가 양의 정수로 주어진다. </p>



<p>세로와 가로의 길이는 최대 100이다. </p>



<p>판의 각 가로줄의 모양이 윗 줄부터 차례로 둘째 줄부터 마지막 줄까지 주어진다. </p>



<p>치즈가 없는 칸은 0, 치즈가 있는 칸은 1로 주어지며 각 숫자 사이에는 빈칸이 하나씩 있다.</p>



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



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p>첫째 줄에는 치즈가 모두 녹아서 없어지는 데 걸리는 시간을 출력하고, </p>



<p>둘째 줄에는 모두 녹기 한 시간 전에 남아있는 치즈조각이 놓여 있는 칸의 개수를 출력한다.</p>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<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="">13 12
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 0 0 0
0 1 1 1 0 0 0 1 1 0 0 0
0 1 1 1 1 1 1 0 0 0 0 0
0 1 1 1 1 1 0 1 1 0 0 0
0 1 1 1 1 0 0 1 1 0 0 0
0 0 1 1 0 0 0 1 1 0 0 0
0 0 1 1 1 1 1 1 1 0 0 0
0 0 1 1 1 1 1 1 1 0 0 0
0 0 1 1 1 1 1 1 1 0 0 0
0 0 1 1 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<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="">3
5</pre>



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



<h3 class="wp-block-heading has-large-font-size">출처</h3>



<p><a href="https://www.acmicpc.net/category/2">Olympiad</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/55">한국정보올림피아드</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/78">KOI 2000</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/391">초등부</a>&nbsp;3번</p>



<ul class="wp-block-list">
<li>문제의 오타를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/compro0317">compro0317</a>,&nbsp;<a href="https://www.acmicpc.net/user/shawn050912">shawn050912</a></li>



<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/jung2381187">jung2381187</a></li>
</ul>



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



<h3 class="wp-block-heading has-large-font-size">알고리즘 분류</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/102">구현</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/7">그래프 이론</a></li>



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



<li><a href="https://www.acmicpc.net/problem/tag/141">시뮬레이션</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/126">너비 우선 탐색</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)"/>



<h2 class="wp-block-heading has-large-font-size">통과된 코드</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>
#include &lt;vector>
using namespace std;
constexpr short MAX = 100;
short _N, _M, _Cheese = 0;
short _DxDy[4][2] = { {1,0},{-1,0},{0,1},{0,-1} };
bool _Map[MAX][MAX];
bool _IsVisted[MAX][MAX];
vector&lt;short> Records;
vector&lt;pair&lt;short, short>> _Next;
queue&lt;pair&lt;short, short>> BFSqueue;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> _N >> _M;
	bool _t;
	for (short i = 0; i &lt; _N; i++)
		for (short j = 0; j &lt; _M; j++) {
			cin >> _t;
			_Map[i][j] = _t;
			if (_t == 1)
				_Cheese++;
		}
	short _time = 0;
	while (true) {
		Records.push_back(_Cheese);
		if (_Cheese == 0)
			break;
		for (short i = 0; i &lt; _N; i++)
			for (short j = 0; j &lt; _M; j++)
				_IsVisted[i][j] = false;
		_Next.clear();
		BFSqueue.push({ 0,0 });
		_IsVisted[0][0] = true;
		while (!BFSqueue.empty()) {
			pair&lt;short, short> _pos = BFSqueue.front();
			BFSqueue.pop();
			for (short i = 0; i &lt; 4; i++) {
				short _dx = _pos.first + _DxDy[i][0];
				short _dy = _pos.second + _DxDy[i][1];

				if (_dx &lt; 0 || _dy &lt; 0 || _dx >= _N || _dy >= _M)
					continue;
				if (_IsVisted[_dx][_dy])
					continue;
				if (_Map[_dx][_dy] == 1) {
					_Next.push_back({ _dx, _dy });
					_IsVisted[_dx][_dy] = true;
					continue;
				}

				_IsVisted[_dx][_dy] = true;
				BFSqueue.push({ _dx, _dy});
			}
		}

		for (auto&amp; it : _Next) {
			_Map[it.first][it.second] = 0;
			_Cheese--;
		}

		_time++;
	}

	cout &lt;&lt; _time &lt;&lt; "\n" &lt;&lt; Records[Records.size() - 2];


	return 0;
}</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="1063" height="86" src="https://lycos7560.com/wp-content/uploads/2023/08/image-24.png" alt="" class="wp-image-36605" style="aspect-ratio:12.28;width:1045px;height:auto" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-24.png 1063w, https://lycos7560.com/wp-content/uploads/2023/08/image-24-300x24.png 300w, https://lycos7560.com/wp-content/uploads/2023/08/image-24-768x62.png 768w" sizes="(max-width: 1063px) 100vw, 1063px" /></figure>



<div style="height:100px" 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="4386247858"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-2636%eb%b2%88-%ec%b9%98%ec%a6%88-c-baekjoon/36604/">백준 2636번 (치즈, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-2636%eb%b2%88-%ec%b9%98%ec%a6%88-c-baekjoon/36604/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2638번 (치즈, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2638%eb%b2%88-%ec%b9%98%ec%a6%88-c-baekjoon/34394/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2638%eb%b2%88-%ec%b9%98%ec%a6%88-c-baekjoon/34394/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sat, 29 Apr 2023 13:13:34 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2638]]></category>
		<category><![CDATA[2638번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[simulation]]></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[백준]]></category>
		<category><![CDATA[백준 2638]]></category>
		<category><![CDATA[백준 2638번]]></category>
		<category><![CDATA[시뮬레이션]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[치즈]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34394</guid>

					<description><![CDATA[<p>백준 2638번 '치즈' 문제에 대한 글입니다.<br />
BFS 탐색을 이용하여 문제를 해결하였습니다.  (This article is about the question of "Cheese" in Baekjoon number 2638.<br />
We solved the problem using BFS navigation.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2638%eb%b2%88-%ec%b9%98%ec%a6%88-c-baekjoon/34394/">백준 2638번 (치즈, C++) [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>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-cf06b050      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#치즈" class="uagb-toc-link__trigger">치즈</a><li class="uagb-toc__list"><a href="#추가-예제" class="uagb-toc-link__trigger">추가 예제</a><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">치즈</h1>



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



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



<figure 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">20960</td><td class="has-text-align-left" data-align="left">9751</td><td class="has-text-align-left" data-align="left">7291</td><td class="has-text-align-left" data-align="left">45.957%</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">N×M의 모눈종이 위에 아주 얇은 치즈가 &lt;그림 1>과 같이 표시되어 있다. </p>



<p class="has-medium-font-size">단, N 은 세로 격자의 수이고, M 은 가로 격자의 수이다. </p>



<p class="has-medium-font-size">이 치즈는 냉동 보관을 해야만 하는데 실내온도에 내어놓으면 공기와 접촉하여 천천히 녹는다. </p>



<p class="has-medium-font-size">그런데 이러한 모눈종이 모양의 치즈에서 각 치즈 격자(작 은 정사각형 모양)의 4변 중에서 적어도 </p>



<p class="has-medium-font-size">2변 이상이 실내온도의 공기와 접촉한 것은 정확히 한시간만에 녹아 없어져 버린다. </p>



<p class="has-medium-font-size">따라서 아래 &lt;그림 1> 모양과 같은 치즈(회색으로 표시된 부분)라면 C로 표시된 모든 치즈 격자는 한 시간 후에 사라진다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="371" height="299" src="https://lycos7560.com/wp-content/uploads/2023/04/image-27.png" alt="" class="wp-image-34396" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-27.png 371w, https://lycos7560.com/wp-content/uploads/2023/04/image-27-300x242.png 300w" sizes="(max-width: 371px) 100vw, 371px" /></figure>



<p class="has-medium-font-size">&lt;그림 1></p>



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



<p class="has-medium-font-size">&lt;그림 2>와 같이 치즈 내부에 있는 공간은 치즈 외부 공기와 접촉하지 않는 것으로 가정한다. </p>



<p class="has-medium-font-size">그러므 로 이 공간에 접촉한 치즈 격자는 녹지 않고 C로 표시된 치즈 격자만 사라진다. </p>



<p class="has-medium-font-size">그러나 한 시간 후, 이 공간으로 외부공기가 유입되면 &lt;그림 3>에서와 같이 C로 표시된 치즈 격자들이 사라지게 된다.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="370" height="301" src="https://lycos7560.com/wp-content/uploads/2023/04/image-28.png" alt="" class="wp-image-34397" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-28.png 370w, https://lycos7560.com/wp-content/uploads/2023/04/image-28-300x244.png 300w" sizes="(max-width: 370px) 100vw, 370px" /></figure>



<p class="has-medium-font-size">&lt;그림 2></p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/04/image-29.png" alt="" class="wp-image-34398" width="380" height="307" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-29.png 371w, https://lycos7560.com/wp-content/uploads/2023/04/image-29-300x243.png 300w" sizes="(max-width: 380px) 100vw, 380px" /></figure>



<p class="has-medium-font-size">&lt;그림 3&gt;</p>



<p class="has-medium-font-size">모눈종이의 맨 가장자리에는 치즈가 놓이지 않는 것으로 가정한다. </p>



<p class="has-medium-font-size">입력으로 주어진 치즈가 모두 녹아 없어지는데 걸리는 정확한 시간을 구하는 프로그램을 작성하시오.</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">첫째 줄에는 모눈종이의 크기를 나타내는 두 개의 정수 N, M (5 ≤ N, M ≤ 100)이 주어진다. </p>



<p class="has-medium-font-size">그 다음 N개의 줄에는 모눈종이 위의 격자에 치즈가 있는 부분은 1로 표시되고, </p>



<p class="has-medium-font-size">치즈가 없는 부분은 0으로 표시된다. 또한, 각 0과 1은 하나의 공백으로 분리되어 있다.</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">출력으로는 주어진 치즈가 모두 녹아 없어지는데 걸리는 정확한 시간을 정수로 첫 줄에 출력한다.</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="">8 9
0 0 0 0 0 0 0 0 0
0 0 0 1 1 0 0 0 0
0 0 0 1 1 0 1 1 0
0 0 1 1 1 1 1 1 0
0 0 1 1 1 1 1 0 0
0 0 1 1 0 1 1 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0</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</pre>



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



<h1 class="wp-block-heading">추가 예제</h1>



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



<h2 class="wp-block-heading">예제 입력 A</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="">7 7
0 0 0 0 0 0 0
0 1 1 0 1 1 0
0 1 1 1 1 1 0
0 0 1 0 1 0 0
0 1 1 1 1 1 0
0 1 1 0 1 1 0
0 0 0 0 0 0 0</pre>



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



<h2 class="wp-block-heading">예제 출력 A</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="">3</pre>



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



<h2 class="wp-block-heading">예제 입력 B</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="">8 9
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 1 1 1 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0</pre>



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



<h2 class="wp-block-heading">예제 출력 B</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="">2</pre>



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



<h2 class="wp-block-heading">예제 입력 C</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 6
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 1 0
0 0 0 0 0 0</pre>



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



<h2 class="wp-block-heading">예제 출력 C</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="">1</pre>



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



<h2 class="wp-block-heading">예제 입력 D</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="">10 10
0 0 0 0 0 0 0 0 0 0
0 1 1 0 0 0 0 1 1 0
0 1 0 1 1 1 1 0 1 0
0 1 0 0 1 1 0 0 1 0
0 1 0 0 1 1 0 0 1 0
0 1 0 0 1 1 0 0 1 0
0 1 0 0 1 0 0 0 1 0
0 1 0 1 1 1 1 0 1 0
0 1 1 0 0 0 0 1 1 0
0 0 0 0 0 0 0 0 0 0</pre>



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



<h2 class="wp-block-heading">예제 출력 D</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</pre>



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



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



<p><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a> > <a href="https://www.acmicpc.net/category/55" target="_blank" rel="noreferrer noopener">한국정보올림피아드</a> > <a href="https://www.acmicpc.net/category/78" target="_blank" rel="noreferrer noopener">KOI 2000</a> > <a href="https://www.acmicpc.net/category/detail/392" target="_blank" rel="noreferrer noopener">중등부</a> 2번</p>



<ul class="wp-block-list">
<li>문제의 오타를 찾은 사람: <a href="https://www.acmicpc.net/user/apjw6112" target="_blank" rel="noreferrer noopener">apjw6112</a></li>



<li>잘못된 데이터를 찾은 사람: <a href="https://www.acmicpc.net/user/tncks0121" target="_blank" rel="noreferrer noopener">tncks0121</a></li>
</ul>



<div style="height:60px" 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/102" target="_blank" rel="noreferrer noopener">구현</a></li>



<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/141" 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)"/>



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



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/04/KakaoTalk_20230429_221047418.jpg" alt="" class="wp-image-34401" width="1060" height="1432" srcset="https://lycos7560.com/wp-content/uploads/2023/04/KakaoTalk_20230429_221047418.jpg 1421w, https://lycos7560.com/wp-content/uploads/2023/04/KakaoTalk_20230429_221047418-222x300.jpg 222w, https://lycos7560.com/wp-content/uploads/2023/04/KakaoTalk_20230429_221047418-768x1038.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/04/KakaoTalk_20230429_221047418-1137x1536.jpg 1137w" sizes="(max-width: 1060px) 100vw, 1060px" /></figure>



<div style="height:40px" 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;vector>
#include &lt;queue>
using namespace std;

int _DxDy[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
int _MapArr[101][101];
bool _isVisited[101][101]; // 방문 체크

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int _N, _M ,_NumCheese = 0, _Res = 0;
    cin >> _N >> _M;
    for (int i = 1; i &lt;= _N; i++) {
        for (int j = 1; j &lt;= _M; j++) {
            cin >> _MapArr[i][j];
            if (_MapArr[i][j]) _NumCheese++; // 치즈의 개수
        }
    }

    while (_NumCheese) { // 치즈가 0이 될때까지 반복
        _Res++; // 시간 ++
        vector&lt;pair&lt;int, int>> _MeltedcheeseV; // 녹을 치즈의 좌표를 저장할 벡터
        for (int i = 1; i &lt;= _N; i++) { // 방문 초기화
            for (int j = 1; j &lt;= _M; j++) {
                _isVisited[i][j] = false;
            }
        }
        // BFS 탐색으로 외부와 닿는 치즈를 찾는다.
        queue&lt;pair&lt;int, int>> myQueue;
        myQueue.push(make_pair(1, 1));
        _MapArr[1][1] = -1; // 외부와 내부의 공기를 구분
        _isVisited[1][1] = true;
        while (!myQueue.empty()) {
            pair&lt;int, int> _CntPos = myQueue.front();
            myQueue.pop();
            for (int k = 0; k &lt; 4; k++) { // 상하 좌우로 검색
                int nx = _CntPos.first + _DxDy[k][0];
                int ny = _CntPos.second + _DxDy[k][1];
                if (nx &lt;= 0 || ny &lt;= 0 || nx > _N || ny > _M) continue; // 범위를 벗어난다면 넘어간다.
                if (_isVisited[nx][ny]) continue; // 방문 했다면 넘어간다.
                _isVisited[nx][ny] = true; // 방문 처리
                if (_MapArr[nx][ny] == 1) { // 만약 치즈라면 다시 큐에 넣을 필요가 없다.
                    _MeltedcheeseV.push_back(make_pair(nx, ny));
                    continue;
                }
                _MapArr[nx][ny] = -1;
                myQueue.push(make_pair(nx, ny));
            }
        }

        for (auto&amp; it : _MeltedcheeseV) { // 표면과 닿아있는 치즈들을 순회
            int _AirNum = 0; // 외부 공기와 닿는 수
            for (int k = 0; k &lt; 4; k++) { // 치즈의 상하 좌우로 검색
                int nx = it.first + _DxDy[k][0];
                int ny = it.second + _DxDy[k][1];
                if (_MapArr[nx][ny] == -1) {
                    _AirNum++;
                    if (_AirNum >= 2) break; // 공기와 닿는 면적이 2이상이면 break;
                }
            }
            if (_AirNum >= 2) { // 닿는 부분이 2개 이상
                _MapArr[it.first][it.second] = 0;
                _NumCheese--; // 치즈의 개수를 줄여준다.
            }
        }

    }

    cout &lt;&lt; _Res;
    
    return 0;
}
</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/04/image-30.png" alt="" class="wp-image-34399" width="1077" height="101" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-30.png 909w, https://lycos7560.com/wp-content/uploads/2023/04/image-30-300x28.png 300w, https://lycos7560.com/wp-content/uploads/2023/04/image-30-768x72.png 768w" sizes="(max-width: 1077px) 100vw, 1077px" /></figure>



<div style="height:100px" 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-2638%eb%b2%88-%ec%b9%98%ec%a6%88-c-baekjoon/34394/">백준 2638번 (치즈, C++) [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-2638%eb%b2%88-%ec%b9%98%ec%a6%88-c-baekjoon/34394/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1076번 (저항, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1076%eb%b2%88-%ec%a0%80%ed%95%ad-c-baekjoon/5713/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1076%eb%b2%88-%ec%a0%80%ed%95%ad-c-baekjoon/5713/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sat, 28 Jan 2023 15:33:10 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1076]]></category>
		<category><![CDATA[1076번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[pair]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1076]]></category>
		<category><![CDATA[백준 1076번]]></category>
		<category><![CDATA[시뮬레이션]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[저항]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5713</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1076번 '저항' 문제에 대한 글입니다. 단순 구현 문제입니다. (This is an article on the 'resistance' problem in BAEKJOON No. 1076. It's a simple implementation problem.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1076%eb%b2%88-%ec%a0%80%ed%95%ad-c-baekjoon/5713/">백준 1076번 (저항, C++) [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"><a href="https://www.acmicpc.net/problem/1076" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1076</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">2 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">25774</td><td class="has-text-align-left" data-align="left">11409</td><td class="has-text-align-left" data-align="left">9784</td><td class="has-text-align-left" data-align="left">44.643%</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">전자 제품에는 저항이 들어간다. </p>



<p class="has-medium-font-size">저항은 색 3개를 이용해서 그 저항이 몇 옴인지 나타낸다. </p>



<p class="has-medium-font-size">처음 색 2개는 저항의 값이고, 마지막 색은 곱해야 하는 값이다. </p>



<p class="has-medium-font-size">저항의 값은 다음 표를 이용해서 구한다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="628" height="777" src="https://lycos7560.com/wp-content/uploads/2023/01/image-35.png" alt="" class="wp-image-5714" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-35.png 628w, https://lycos7560.com/wp-content/uploads/2023/01/image-35-242x300.png 242w" sizes="(max-width: 628px) 100vw, 628px" /></figure>



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



<p class="has-medium-font-size">예를 들어, 저항의 색이 yellow, violet, red였다면 저항의 값은 4,700이 된다.</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">첫째 줄에 첫 번째 색, 둘째 줄에 두 번째 색, 셋째 줄에 세 번째 색이 주어진다. </p>



<p class="has-medium-font-size">위의 표에 있는 색만 입력으로 주어진다.</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">입력으로 주어진 저항의 저항값을 계산하여 첫째 줄에 출력한다.</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="">yellow
violet
red</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="">4700</pre>



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



<h2 class="wp-block-heading">예제 입력 2</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="">orange
red
blue</pre>



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



<h2 class="wp-block-heading">예제 출력 2</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="">32000000</pre>



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



<h2 class="wp-block-heading">예제 입력 3</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="">white
white
white</pre>



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



<h2 class="wp-block-heading">예제 출력 3</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="">99000000000</pre>



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



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



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



<li>어색한 표현을 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/shiroed1211" target="_blank" rel="noreferrer noopener">shiroed1211</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/102">구현</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">단순 구현문제</p>



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



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



<div style="height:40px" 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;map>

using namespace std;

string str;

long long int result;

multimap&lt;string, pair&lt;int, long long int>> mMap = { 
		{"black", make_pair(0, 1)},
		{"brown", make_pair(1, 10)},
		{"red", make_pair(2, 100)},
		{"orange", make_pair(3, 1000)},
		{"yellow", make_pair(4, 10000)},
		{"green", make_pair(5, 100000)},
		{"blue", make_pair(6, 1000000)},
		{"violet", make_pair(7, 10000000)},
		{"grey", make_pair(8, 100000000)},
		{"white", make_pair(9, 1000000000)}
};

int main()
{
	cin >> str;
	result += (mMap.find(str)->second.first * 10);
	cin >> str;
	result += (mMap.find(str)->second.first);
	cin >> str;
	result *= (mMap.find(str)->second.second);
	cout &lt;&lt; result;

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1248" height="126" src="https://lycos7560.com/wp-content/uploads/2023/01/image-36.png" alt="" class="wp-image-5715" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-36.png 1248w, https://lycos7560.com/wp-content/uploads/2023/01/image-36-300x30.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-36-768x78.png 768w" sizes="(max-width: 1248px) 100vw, 1248px" /></figure>



<div style="height:40px" 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-1076%eb%b2%88-%ec%a0%80%ed%95%ad-c-baekjoon/5713/">백준 1076번 (저항, C++) [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-1076%eb%b2%88-%ec%a0%80%ed%95%ad-c-baekjoon/5713/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 16236번 (아기 상어, C++, Simulation) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-16236%eb%b2%88-%ec%95%84%ea%b8%b0-%ec%83%81%ec%96%b4-c-simulation-baekjoon/5687/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-16236%eb%b2%88-%ec%95%84%ea%b8%b0-%ec%83%81%ec%96%b4-c-simulation-baekjoon/5687/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sat, 28 Jan 2023 11:23:16 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[16236]]></category>
		<category><![CDATA[16236번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[tuple]]></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[백준]]></category>
		<category><![CDATA[백준 16236]]></category>
		<category><![CDATA[백준 16236번]]></category>
		<category><![CDATA[시뮬레이션]]></category>
		<category><![CDATA[아기 상어]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[큐]]></category>
		<category><![CDATA[튜플]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5687</guid>

					<description><![CDATA[<p>백준 16236번 '아기 상어' 문제에 대한 글입니다. 'BFS 탐색'을 이용하여 해결하였습니다. (This is Baekjun 16236 about the 'Baby Shark' problem. Resolved using 'BFS Search'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-16236%eb%b2%88-%ec%95%84%ea%b8%b0-%ec%83%81%ec%96%b4-c-simulation-baekjoon/5687/">백준 16236번 (아기 상어, C++, Simulation) [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"><a href="https://www.acmicpc.net/problem/16236" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/16236</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">2 초</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">52413</td><td class="has-text-align-left" data-align="left">23961</td><td class="has-text-align-left" data-align="left">14308</td><td class="has-text-align-left" data-align="left">42.311%</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">N×N 크기의 공간에 물고기 M마리와 아기 상어 1마리가 있다. </p>



<p class="has-medium-font-size">공간은 1×1 크기의 정사각형 칸으로 나누어져 있다. </p>



<p class="has-medium-font-size">한 칸에는 물고기가 최대 1마리 존재한다.</p>



<p class="has-medium-font-size">아기 상어와 물고기는 모두 크기를 가지고 있고, 이 크기는 자연수이다. </p>



<p class="has-medium-font-size">가장 처음에 아기 상어의 크기는 2이고, 아기 상어는 1초에 상하좌우로 인접한 한 칸씩 이동한다.</p>



<p class="has-medium-font-size">아기 상어는 자신의 크기보다 큰 물고기가 있는 칸은 지나갈 수 없고, 나머지 칸은 모두 지나갈 수 있다. </p>



<p class="has-medium-font-size">아기 상어는 자신의 크기보다 작은 물고기만 먹을 수 있다. </p>



<p class="has-medium-font-size">따라서, 크기가 같은 물고기는 먹을 수 없지만, 그 물고기가 있는 칸은 지나갈 수 있다.</p>



<p class="has-medium-font-size">아기 상어가 어디로 이동할지 결정하는 방법은 아래와 같다.</p>



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



<p class="has-medium-font-size"><strong>더 이상 먹을 수 있는 물고기가 공간에 없다면 아기 상어는 엄마 상어에게 도움을 요청한다.</strong></p>



<p class="has-medium-font-size"><strong>먹을 수 있는 물고기가 1마리라면, 그 물고기를 먹으러 간다.</strong></p>



<p class="has-medium-font-size"><strong>먹을 수 있는 물고기가 1마리보다 많다면, 거리가 가장 가까운 물고기를 먹으러 간다.</strong></p>



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



<p class="has-medium-font-size"><strong>&#8211; 거리는 아기 상어가 있는 칸에서 물고기가 있는 칸으로 이동할 때, 지나야하는 칸의 개수의 최솟값이다.</strong></p>



<p class="has-medium-font-size"><strong>&#8211; 거리가 가까운 물고기가 많다면, 가장&nbsp;위에 있는 물고기, 그러한 물고기가 여러마리라면, 가장 왼쪽에 있는 물고기를 먹는다.</strong></p>



<p class="has-medium-font-size"><strong>&#8211; 아기 상어의 이동은 1초 걸리고, 물고기를 먹는데 걸리는 시간은 없다고 가정한다. </strong></p>



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



<p class="has-medium-font-size">즉, 아기 상어가 먹을 수 있는 물고기가 있는 칸으로 이동했다면, 이동과 동시에 물고기를 먹는다. 물고기를 먹으면, 그 칸은 빈 칸이 된다.</p>



<p class="has-medium-font-size">아기 상어는 자신의 크기와 같은 수의 물고기를 먹을 때 마다 크기가 1 증가한다. 예를 들어, 크기가 2인 아기 상어는 물고기를 2마리 먹으면 크기가 3이 된다.</p>



<p class="has-medium-font-size">공간의 상태가 주어졌을 때, 아기 상어가 몇 초 동안 엄마 상어에게 도움을 요청하지 않고 물고기를 잡아먹을 수&nbsp;있는지 구하는 프로그램을 작성하시오.</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">첫째 줄에 공간의 크기 N(2&nbsp;≤ N ≤ 20)이 주어진다.</p>



<p class="has-medium-font-size">둘째 줄부터 N개의 줄에 공간의 상태가 주어진다. </p>



<p class="has-medium-font-size">공간의 상태는 0, 1, 2, 3, 4, 5, 6, 9로 이루어져 있고, 아래와 같은 의미를 가진다.</p>



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



<p class="has-medium-font-size"><strong>0: 빈 칸</strong></p>



<p class="has-medium-font-size"><strong>1, 2, 3, 4, 5, 6: 칸에 있는 물고기의 크기</strong></p>



<p class="has-medium-font-size"><strong>9: 아기 상어의 위치</strong></p>



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



<p class="has-medium-font-size">아기 상어는 공간에 한 마리 있다.</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">첫째 줄에 아기 상어가 엄마 상어에게 도움을 요청하지 않고 물고기를 잡아먹을 수 있는 시간을 출력한다.</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="">3
0 0 0
0 0 0
0 9 0</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="">0</pre>



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



<h2 class="wp-block-heading">예제 입력 2</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="">3
0 0 1
0 0 0
0 9 0</pre>



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



<h2 class="wp-block-heading">예제 출력 2</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="">3</pre>



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



<h2 class="wp-block-heading">예제 입력 3</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
4 3 2 1
0 0 0 0
0 0 9 0
1 2 3 4</pre>



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



<h2 class="wp-block-heading">예제 출력 3</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="">14</pre>



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



<h2 class="wp-block-heading">예제 입력 4</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="">6
5 4 3 2 3 4
4 3 2 3 4 5
3 2 9 5 6 6
2 1 2 3 4 5
3 2 1 6 5 4
6 6 6 6 6 6</pre>



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



<h2 class="wp-block-heading">예제 출력 4</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="">60</pre>



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



<h2 class="wp-block-heading">예제 입력 5</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="">6
6 0 6 0 6 1
0 0 0 0 0 2
2 3 4 5 6 6
0 0 0 0 0 2
0 2 0 0 0 0
3 9 3 0 0 1</pre>



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



<h2 class="wp-block-heading">예제 출력 5</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="">48</pre>



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



<h2 class="wp-block-heading">예제 입력 6</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="">6
1 1 1 1 1 1
2 2 6 2 2 3
2 2 5 2 2 3
2 2 2 4 6 3
0 0 0 0 0 6
0 0 0 0 0 9</pre>



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



<h2 class="wp-block-heading">예제 출력 6</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="">39</pre>



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



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



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



<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/djm03178" target="_blank" rel="noreferrer noopener">djm03178</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/102" target="_blank" rel="noreferrer noopener">구현</a></li>



<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/141" 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">문제의 조건을 이해 못해서 해결하는데 엄청 시간이 걸렸다.</p>



<p class="has-medium-font-size">특히 맵에 먹을 수 있는 물고기가 여러 마리 일때 조건에서 막혔는데</p>



<p class="has-medium-font-size">예제와 글을 계속 읽어보면서 겨우 이해했다.</p>



<p class="has-medium-font-size">결론은 <strong>거리가 가장 가까운 물고기들 중에서  가장 위쪽에 있으면서 좌측에 있는 물고기를 픽</strong>하는 것</p>



<p class="has-medium-font-size">이 문제의 설명이 너무 잘되어있는 글이 있어서 첨부한다.</p>



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



<p><a href="https://www.acmicpc.net/board/view/100687" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/board/view/100687</a></p>



<figure class="wp-block-image size-full"><img decoding="async" width="1599" height="962" src="https://lycos7560.com/wp-content/uploads/2023/01/image-32.png" alt="" class="wp-image-5689" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-32.png 1599w, https://lycos7560.com/wp-content/uploads/2023/01/image-32-300x180.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-32-768x462.png 768w, https://lycos7560.com/wp-content/uploads/2023/01/image-32-1536x924.png 1536w" sizes="(max-width: 1599px) 100vw, 1599px" /></figure>



<p> </p>



<figure class="wp-block-image size-full"><img decoding="async" width="1643" height="1140" src="https://lycos7560.com/wp-content/uploads/2023/01/image-33.png" alt="" class="wp-image-5690" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-33.png 1643w, https://lycos7560.com/wp-content/uploads/2023/01/image-33-300x208.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-33-768x533.png 768w, https://lycos7560.com/wp-content/uploads/2023/01/image-33-1536x1066.png 1536w" sizes="(max-width: 1643px) 100vw, 1643px" /></figure>



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



<p class="has-medium-font-size">위의 설명을 구현하기 위해서</p>



<p class="has-medium-font-size">1. 상어의 위치에서 BFS 탐색을 통하여 상어가 먹을 수 있는 가장 가까운 물고기의 위치를 저장한다. </p>



<p class="has-medium-font-size">(탐색의 방향은 <strong>상/좌/우/하</strong>)</p>



<p class="has-medium-font-size">2.  상어가 먹을 수 있는 물고기의 위치에서 <strong>가장 위쪽에 있으면서 좌측에 있는 물고기</strong>를 선택한다.</p>



<p class="has-medium-font-size">3. 해당 물고기의 위치로 상어를 옮기고 물고기를 제거하며 상어의 크기를 업데이트 해준다.</p>



<p class="has-medium-font-size">4. 해당 위치까지 얼마나 걸렸는지 카운트 해준다.</p>



<p class="has-medium-font-size">5. <strong>상어가 먹을 수 있는 물고기가 없을 때까지</strong> 1 &#8211; 4 를 반복한다.</p>



<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)"/>



<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>
#include &lt;tuple>

using namespace std;

// 최대 범위 
constexpr int MAX = 20;

// 상/좌/우/하
int dxdy[4][2] = { {-1, 0}, {0, -1}, {0, 1}, {1, 0} };

pair&lt;int, int> Shark; // 상어 크기, 경험치?

tuple&lt;int, int, int> posShark; // 상어의 x, y위치 / 시간

tuple&lt;int, int, int> tempT;

int N, dx, dy;

int map[MAX][MAX]; // 맵

bool eatMap[MAX][MAX]; // 먹을 수 있는 물고기 체크

bool mapCheck[MAX][MAX]; // BFS 방문 체크에 사용

// BFS 탐색, 반환값음 상어의 위치와 시간
tuple&lt;int, int, int> SharkBFS()
{
    queue&lt;tuple&lt;int, int, int>> myQ;

    // 방문처리 초기화
    fill(&amp;mapCheck[0][0], &amp;mapCheck[N - 1][N], false);
    fill(&amp;eatMap[0][0], &amp;eatMap[N - 1][N], false);

    myQ.push(posShark);
    mapCheck[get&lt;0>(posShark)][get&lt;1>(posShark)] = true;

    int dis = 99999;
    while (!myQ.empty()) {
        tempT = myQ.front();
        myQ.pop();

        // 상/하/좌/우를 탐색하기 위한 반복문
        for (int i = 0; i &lt; 4; i++) {
            dx = get&lt;0>(tempT) + dxdy[i][0];
            dy = get&lt;1>(tempT) + dxdy[i][1];

            // 문제의 범위를 벗어나는 경우 => 넘어간다.
            if (dx &lt; 0 || dy &lt; 0 || dx >= N || dy >= N) continue;
            // 이미 방문한 곳 일 경우와 해당 칸의 물고기가 상어보다 클 경우 => 넘어간다.
            if (mapCheck[dx][dy] == true || map[dx][dy] > Shark.first) continue;

            // 상어가 더 크고, 빈 공간이 아니라면 
            if (map[dx][dy] &lt; Shark.first &amp;&amp; map[dx][dy] != 0 ) {

                if (get&lt;2>(tempT) + 1 &lt;= dis) {
                    eatMap[dx][dy] = true;
                    dis = get&lt;2>(tempT) + 1;
                }
            }

            mapCheck[dx][dy] = true; // 방문처리
            myQ.push(make_tuple(dx, dy, get&lt;2>(tempT) + 1)); // 탐색 Q에 넣기
        }
    }

    // 먹을 수 있는 물고기들 중에서 
    // 가장 위, 좌측에 있는 물고기를 선택한다.
    for (int i = 0; i &lt; N; i++) {
        for (int j = 0; j &lt; N; j++) {
            if (eatMap[i][j] == true) {
                Shark.second++;
                map[i][j] = 0;
                if (Shark.first == Shark.second) {
                    Shark.first++;
                    Shark.second = 0;
                }

                return make_tuple(i, j, dis);
            }
        }
    }
    
    // 없다면 기존 상어의 위치를 반환한다.
    return posShark;
}


int main()
{
    ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
    // cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
    cin.tie(NULL);
    cout.tie(NULL);

    Shark = make_pair(2, 0);

    cin >> N;
    for (int i = 0; i &lt; N; i++) {
        for (int j = 0; j &lt; N; j++) {
            cin >> map[i][j];
            if (map[i][j] == 9) { // 상어의 위치를 저장
                posShark = make_tuple(i, j, 0);
                map[i][j] = 0;
            }
        }
    }

    bool check = true;
    while (check) {
        check = false;
        for (int i = 0; i &lt; N &amp;&amp; !check; i++) {
            for (int j = 0; j &lt; N &amp;&amp; !check; i++) {
                if (map[i][j] >= 1) check = true;
            }
        }

        tempT = SharkBFS();
        
        // BFS 탐색 후에도 상어의 움직임이 없다면 먹을 수 있는 물고기가 없다.
        if (get&lt;2>(tempT) == get&lt;2>(posShark)) break;
        else posShark = tempT;
  
    }

    cout &lt;&lt; get&lt;2>(posShark);

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1250" height="114" src="https://lycos7560.com/wp-content/uploads/2023/01/image-31.png" alt="" class="wp-image-5688" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-31.png 1250w, https://lycos7560.com/wp-content/uploads/2023/01/image-31-300x27.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-31-768x70.png 768w" sizes="(max-width: 1250px) 100vw, 1250px" /></figure>



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



<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"><strong>디버깅</strong> </p>



<p class="has-small-font-size"><a href="https://www.acmicpc.net/board/view/100687" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/board/view/100687</a></p>



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



<h3 class="wp-block-heading">예제 입력 4</h3>



<p class="has-medium-font-size">여기서부터는 시뮬레이션이 매우 길기 때문에 디버깅 출력으로 대신하겠습니다.</p>



<p class="has-medium-font-size">또한, 가독성을 위해 상어의 위치는 9 대신 &#8220;■&#8221;, 물고기가 없는 위치는 0 대신 &#8220;.&#8221; 로 표기했습니다.</p>



<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 4 3 2 3 4
4 3 2 3 4 5
3 2 ■ 5 6 6
2 1 2 3 4 5
3 2 1 6 5 4
6 6 6 6 6 6
0s / Lv. 2 (Exp 0 / 2)


5 4 3 2 3 4 
4 3 2 3 4 5 
3 2 . 5 6 6 
2 ■ 2 3 4 5 
3 2 1 6 5 4 
6 6 6 6 6 6 
2s / Lv. 2 (Exp 1 / 2)


5 4 3 2 3 4 
4 3 2 3 4 5 
3 2 . 5 6 6 
2 . 2 3 4 5 
3 2 ■ 6 5 4 
6 6 6 6 6 6 
4s / Lv. 3 (Exp 0 / 3)


5 4 3 2 3 4 
4 3 2 3 4 5 
3 2 . 5 6 6 
2 . ■ 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
5s / Lv. 3 (Exp 1 / 3)


5 4 3 2 3 4 
4 3 ■ 3 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
7s / Lv. 3 (Exp 2 / 3)


5 4 3 ■ 3 4 
4 3 . 3 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
9s / Lv. 4 (Exp 0 / 4)


5 4 ■ . 3 4 
4 3 . 3 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
10s / Lv. 4 (Exp 1 / 4)


5 4 . . ■ 4 
4 3 . 3 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
12s / Lv. 4 (Exp 2 / 4)


5 4 . . . 4 
4 3 . ■ 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
14s / Lv. 4 (Exp 3 / 4)


5 4 . . . 4 
4 ■ . . 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
16s / Lv. 5 (Exp 0 / 5)


5 ■ . . . 4 
4 . . . 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
17s / Lv. 5 (Exp 1 / 5)


5 . . . . 4 
■ . . . 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
19s / Lv. 5 (Exp 2 / 5)


5 . . . . 4 
. . . . 4 5 
■ 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
20s / Lv. 5 (Exp 3 / 5)


5 . . . . 4 
. . . . 4 5 
. ■ . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
21s / Lv. 5 (Exp 4 / 5)


5 . . . . 4 
. . . . 4 5 
. . . 5 6 6 
■ . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
23s / Lv. 6 (Exp 0 / 6)


5 . . . . 4 
. . . . 4 5 
. . . 5 6 6 
. . . 3 4 5 
■ 2 . 6 5 4 
6 6 6 6 6 6 
24s / Lv. 6 (Exp 1 / 6)


5 . . . . 4 
. . . . 4 5 
. . . 5 6 6 
. . . 3 4 5 
. ■ . 6 5 4 
6 6 6 6 6 6 
25s / Lv. 6 (Exp 2 / 6)


5 . . . . 4 
. . . . 4 5 
. . . 5 6 6 
. . . ■ 4 5 
. . . 6 5 4 
6 6 6 6 6 6 
28s / Lv. 6 (Exp 3 / 6)


5 . . . . 4 
. . . . 4 5 
. . . ■ 6 6 
. . . . 4 5 
. . . 6 5 4 
6 6 6 6 6 6 
29s / Lv. 6 (Exp 4 / 6)


5 . . . . 4 
. . . . ■ 5 
. . . . 6 6 
. . . . 4 5 
. . . 6 5 4 
6 6 6 6 6 6 
31s / Lv. 6 (Exp 5 / 6)


5 . . . . 4 
. . . . . ■ 
. . . . 6 6 
. . . . 4 5 
. . . 6 5 4 
6 6 6 6 6 6 
32s / Lv. 7 (Exp 0 / 7)


5 . . . . ■ 
. . . . . . 
. . . . 6 6 
. . . . 4 5 
. . . 6 5 4 
6 6 6 6 6 6 
33s / Lv. 7 (Exp 1 / 7)


5 . . . . . 
. . . . . . 
. . . . 6 ■ 
. . . . 4 5 
. . . 6 5 4 
6 6 6 6 6 6 
35s / Lv. 7 (Exp 2 / 7)


5 . . . . . 
. . . . . . 
. . . . ■ . 
. . . . 4 5 
. . . 6 5 4 
6 6 6 6 6 6 
36s / Lv. 7 (Exp 3 / 7)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . ■ 5 
. . . 6 5 4 
6 6 6 6 6 6 
37s / Lv. 7 (Exp 4 / 7)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . ■ 
. . . 6 5 4 
6 6 6 6 6 6 
38s / Lv. 7 (Exp 5 / 7)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . 6 5 ■ 
6 6 6 6 6 6 
39s / Lv. 7 (Exp 6 / 7)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . 6 ■ . 
6 6 6 6 6 6 
40s / Lv. 8 (Exp 0 / 8)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . ■ . . 
6 6 6 6 6 6 
41s / Lv. 8 (Exp 1 / 8)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
6 6 6 ■ 6 6 
42s / Lv. 8 (Exp 2 / 8)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
6 6 ■ . 6 6 
43s / Lv. 8 (Exp 3 / 8)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
6 ■ . . 6 6 
44s / Lv. 8 (Exp 4 / 8)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
■ . . . 6 6 
45s / Lv. 8 (Exp 5 / 8)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . ■ 6 
49s / Lv. 8 (Exp 6 / 8)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . ■ 
50s / Lv. 8 (Exp 7 / 8)


■ . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
60s / Lv. 9 (Exp 0 / 9)</pre>



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



<p class="has-medium-font-size">따라서 답은 60초입니다.</p>



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



<h3 class="wp-block-heading">예제 입력 5</h3>



<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="">6 . 6 . 6 1
. . . . . 2
2 3 4 5 6 6
. . . . . 2
. 2 . . . .
3 ■ 3 . . 1
0s / Lv. 2 (Exp 0 / 2)


6 . 6 . 6 1 
. . . . . 2 
2 3 4 5 6 6 
. . . . . 2 
. 2 . . . . 
3 . 3 . . ■ 
6s / Lv. 2 (Exp 1 / 2)


6 . 6 . 6 ■ 
. . . . . 2 
2 3 4 5 6 6 
. . . . . 2 
. 2 . . . . 
3 . 3 . . . 
21s / Lv. 3 (Exp 0 / 3)


6 . 6 . 6 . 
. . . . . ■ 
2 3 4 5 6 6 
. . . . . 2 
. 2 . . . . 
3 . 3 . . . 
22s / Lv. 3 (Exp 1 / 3)


6 . 6 . 6 . 
. . . . . . 
■ 3 4 5 6 6 
. . . . . 2 
. 2 . . . . 
3 . 3 . . . 
28s / Lv. 3 (Exp 2 / 3)


6 . 6 . 6 . 
. . . . . . 
. 3 4 5 6 6 
. . . . . 2 
. ■ . . . . 
3 . 3 . . . 
31s / Lv. 4 (Exp 0 / 4)


6 . 6 . 6 . 
. . . . . . 
. ■ 4 5 6 6 
. . . . . 2 
. . . . . . 
3 . 3 . . . 
33s / Lv. 4 (Exp 1 / 4)


6 . 6 . 6 . 
. . . . . . 
. . 4 5 6 6 
. . . . . 2 
. . . . . . 
■ . 3 . . . 
37s / Lv. 4 (Exp 2 / 4)


6 . 6 . 6 . 
. . . . . . 
. . 4 5 6 6 
. . . . . 2 
. . . . . . 
. . ■ . . . 
39s / Lv. 4 (Exp 3 / 4)


6 . 6 . 6 . 
. . . . . . 
. . 4 5 6 6 
. . . . . ■ 
. . . . . . 
. . . . . . 
44s / Lv. 5 (Exp 0 / 5)


6 . 6 . 6 . 
. . . . . . 
. . ■ 5 6 6 
. . . . . . 
. . . . . . 
. . . . . . 
48s / Lv. 5 (Exp 1 / 5)</pre>



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



<p class="has-medium-font-size">따라서 답은 48초입니다.</p>



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



<h3 class="wp-block-heading">예제 입력 6</h3>



<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="">1 1 1 1 1 1 
2 2 6 2 2 3 
2 2 5 2 2 3 
2 2 2 4 6 3 
. . . . . 6 
. . . . . ■ 
0s / Lv. 2 (Exp 0 / 2)


1 ■ 1 1 1 1 
2 2 6 2 2 3 
2 2 5 2 2 3 
2 2 2 4 6 3 
. . . . . 6 
. . . . . . 
9s / Lv. 2 (Exp 1 / 2)


■ . 1 1 1 1 
2 2 6 2 2 3 
2 2 5 2 2 3 
2 2 2 4 6 3 
. . . . . 6 
. . . . . . 
10s / Lv. 3 (Exp 0 / 3)


. . 1 1 1 1 
■ 2 6 2 2 3 
2 2 5 2 2 3 
2 2 2 4 6 3 
. . . . . 6 
. . . . . . 
11s / Lv. 3 (Exp 1 / 3)


. . 1 1 1 1 
. ■ 6 2 2 3 
2 2 5 2 2 3 
2 2 2 4 6 3 
. . . . . 6 
. . . . . . 
12s / Lv. 3 (Exp 2 / 3)


. . 1 1 1 1 
. . 6 2 2 3 
2 ■ 5 2 2 3 
2 2 2 4 6 3 
. . . . . 6 
. . . . . . 
13s / Lv. 4 (Exp 0 / 4)


. . 1 1 1 1 
. . 6 2 2 3 
■ . 5 2 2 3 
2 2 2 4 6 3 
. . . . . 6 
. . . . . . 
14s / Lv. 4 (Exp 1 / 4)


. . 1 1 1 1 
. . 6 2 2 3 
. . 5 2 2 3 
■ 2 2 4 6 3 
. . . . . 6 
. . . . . . 
15s / Lv. 4 (Exp 2 / 4)


. . 1 1 1 1 
. . 6 2 2 3 
. . 5 2 2 3 
. ■ 2 4 6 3 
. . . . . 6 
. . . . . . 
16s / Lv. 4 (Exp 3 / 4)


. . 1 1 1 1 
. . 6 2 2 3 
. . 5 2 2 3 
. . ■ 4 6 3 
. . . . . 6 
. . . . . . 
17s / Lv. 5 (Exp 0 / 5)


. . 1 1 1 1 
. . 6 2 2 3 
. . 5 2 2 3 
. . . ■ 6 3 
. . . . . 6 
. . . . . . 
18s / Lv. 5 (Exp 1 / 5)


. . 1 1 1 1 
. . 6 2 2 3 
. . 5 ■ 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
19s / Lv. 5 (Exp 2 / 5)


. . 1 1 1 1 
. . 6 ■ 2 3 
. . 5 . 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
20s / Lv. 5 (Exp 3 / 5)


. . 1 ■ 1 1 
. . 6 . 2 3 
. . 5 . 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
21s / Lv. 5 (Exp 4 / 5)


. . ■ . 1 1 
. . 6 . 2 3 
. . 5 . 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
22s / Lv. 6 (Exp 0 / 6)


. . . . ■ 1 
. . 6 . 2 3 
. . 5 . 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
24s / Lv. 6 (Exp 1 / 6)


. . . . . ■ 
. . 6 . 2 3 
. . 5 . 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
25s / Lv. 6 (Exp 2 / 6)


. . . . . . 
. . 6 . 2 ■ 
. . 5 . 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
26s / Lv. 6 (Exp 3 / 6)


. . . . . . 
. . 6 . ■ . 
. . 5 . 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
27s / Lv. 6 (Exp 4 / 6)


. . . . . . 
. . 6 . . . 
. . 5 . ■ 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
28s / Lv. 6 (Exp 5 / 6)


. . . . . . 
. . 6 . . . 
. . 5 . . ■ 
. . . . 6 3 
. . . . . 6 
. . . . . . 
29s / Lv. 7 (Exp 0 / 7)


. . . . . . 
. . 6 . . . 
. . 5 . . . 
. . . . 6 ■ 
. . . . . 6 
. . . . . . 
30s / Lv. 7 (Exp 1 / 7)


. . . . . . 
. . 6 . . . 
. . 5 . . . 
. . . . ■ . 
. . . . . 6 
. . . . . . 
31s / Lv. 7 (Exp 2 / 7)


. . . . . . 
. . 6 . . . 
. . 5 . . . 
. . . . . . 
. . . . . ■ 
. . . . . . 
33s / Lv. 7 (Exp 3 / 7)


. . . . . . 
. . 6 . . . 
. . ■ . . . 
. . . . . . 
. . . . . . 
. . . . . . 
38s / Lv. 7 (Exp 4 / 7)


. . . . . . 
. . ■ . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
39s / Lv. 7 (Exp 5 / 7)</pre>



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



<p class="has-medium-font-size">따라서 답은 39초입니다.</p>



<div style="height:100px" 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-16236%eb%b2%88-%ec%95%84%ea%b8%b0-%ec%83%81%ec%96%b4-c-simulation-baekjoon/5687/">백준 16236번 (아기 상어, C++, Simulation) [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-16236%eb%b2%88-%ec%95%84%ea%b8%b0-%ec%83%81%ec%96%b4-c-simulation-baekjoon/5687/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 18500번 (미네랄 2, C++, Simulation) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-18500%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-2-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5533/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-18500%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-2-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5533/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 25 Jan 2023 09:53:37 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[18500]]></category>
		<category><![CDATA[18500번]]></category>
		<category><![CDATA[2933]]></category>
		<category><![CDATA[2933번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cin.tie(NULL)]]></category>
		<category><![CDATA[cout.tie(NULL)]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false)]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></category>
		<category><![CDATA[simulation]]></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[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[리스트]]></category>
		<category><![CDATA[미네랄]]></category>
		<category><![CDATA[미네랄 2]]></category>
		<category><![CDATA[반례]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 18500]]></category>
		<category><![CDATA[백준 18500번]]></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[추가반례]]></category>
		<category><![CDATA[추가예제]]></category>
		<category><![CDATA[컴파일 에러]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[틀렸습니다]]></category>
		<category><![CDATA[틀렸습니다!]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5533</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 18500번 '미네랄 2' 문제에 대한 글입니다. '그래프 Search'을 이용하여 해결하였습니다.<br />
추가적인 테스트 케이스를 제시합니다. (This is BAEKJOON's 18500 article on the 'Mineral 2' problem. I solved it using 'Graph Search'.<br />
Present additional test cases.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-18500%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-2-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5533/">백준 18500번 (미네랄 2, C++, Simulation) / 추가 반례 [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">미네랄 2</h1>



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



<div style="height:46px" 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">512 MB</td><td class="has-text-align-left" data-align="left">2109</td><td class="has-text-align-left" data-align="left">713</td><td class="has-text-align-left" data-align="left">549</td><td class="has-text-align-left" data-align="left">34.355%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">창영과 상근은 한 동굴을 놓고 소유권을 주장하고 있다. </p>



<p class="has-medium-font-size">두 사람은 막대기를 서로에게 던지는 방법을 이용해 누구의 소유 인지를 결정하기로 했다. </p>



<p class="has-medium-font-size">싸움은 동굴에서 벌어진다. 동굴에는 미네랄이 저장되어 있으며, 던진 막대기가 미네랄을 파괴할 수도 있다.</p>



<p class="has-medium-font-size">동굴은 R행 C열로 나타낼 수 있으며, R×C칸으로 이루어져 있다. </p>



<p class="has-medium-font-size">각 칸은 비어있거나 미네랄을 포함하고 있으며, 네 방향 중 하나로 인접한 미네랄이 포함된 두 칸은 같은 클러스터이다.</p>



<p class="has-medium-font-size">창영은 동굴의 왼쪽에 서있고, 상근은 오른쪽에 서있다. 두 사람은 턴을 번갈아가며 막대기를 던진다. </p>



<p class="has-medium-font-size">막대를 던지기 전에 던질 높이를 정해야 한다. 막대는 땅과 수평을 이루며 날아간다.</p>



<p class="has-medium-font-size">막대가 날아가다가 미네랄을 만나면, 그 칸에 있는 미네랄은 모두 파괴되고 막대는 그 자리에서 이동을 멈춘다.</p>



<p class="has-medium-font-size">미네랄이 파괴된 이후에 남은 클러스터가 분리될 수도 있다.  </p>



<p class="has-medium-font-size">새롭게 생성된 클러스터가 떠 있는 경우에는 중력에 의해서 바닥으로 떨어지게 된다. </p>



<p class="has-medium-font-size">떨어지는 동안 클러스터의 모양은 변하지 않는다. 클러스터는 다른 클러스터나 땅을 만나기 전까지 계속해서 떨어진다. </p>



<p class="has-medium-font-size">클러스터는 다른 클러스터 위에 떨어질 수 있고, 그 이후에는 합쳐지게 된다.</p>



<p class="has-medium-font-size">동굴에 있는 미네랄의 모양과 두 사람이 던진 막대의 높이가 주어진다. </p>



<p class="has-medium-font-size">모든 막대를 던지고 난 이후에 미네랄 모양을 구하는 프로그램을 작성하시오.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 동굴의 크기 R과 C가 주어진다. (1 ≤ R,C ≤ 100)</p>



<p class="has-medium-font-size">다음 R개 줄에는 C개의 문자가 주어지며, &#8216;.&#8217;는 빈 칸, &#8216;x&#8217;는 미네랄을 나타낸다.</p>



<p class="has-medium-font-size">다음 줄에는 막대를 던진 횟수 N이 주어진다. (1 ≤ N ≤ 100)</p>



<p class="has-medium-font-size">마지막 줄에는 막대를 던진 높이가 주어지며, 공백으로 구분되어져 있다. </p>



<p class="has-medium-font-size">모든 높이는 1과 R사이이며, 높이 1은 행렬의 가장 바닥, R은 가장 위를 의미한다. <br><br>첫 번째 막대는 왼쪽에서 오른쪽으로 던졌으며, 두 번째는 오른쪽에서 왼쪽으로, 이와 같은 식으로 번갈아가며 던진다.</p>



<p class="has-medium-font-size">공중에 떠 있는 미네랄 클러스터는 없으며, 두 개 또는 그 이상의 클러스터가 동시에 떨어지는 경우도 없다. </p>



<p class="has-medium-font-size"><s>클러스터가 떨어질 때,&nbsp;그 클러스터 각 열의 맨 아래 부분 중 하나가 바닥 또는 미네랄 위로 떨어지는 입력만 주어진다.</s></p>



<p>(2933번 문제와 차이)</p>



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



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



<p class="has-medium-font-size">입력 형식과 같은 형식으로 미네랄 모양을 출력한다.</p>



<div style="height:41px" 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 6
......
..xx..
..x...
..xx..
.xxxx.
1
3</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="">......
......
..xx..
..xx..
.xxxx.</pre>



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



<h2 class="wp-block-heading">예제 입력 2</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="">8 8
........
........
...x.xx.
...xxx..
..xxx...
..x.xxx.
..x...x.
.xxx..x.
5
6 6 4 3 1</pre>



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



<h2 class="wp-block-heading">예제 출력 2</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="">........
........
........
........
.....x..
..xxxx..
..xxx.x.
..xxxxx.</pre>



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



<h2 class="wp-block-heading">예제 입력 3</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="">7 6
......
......
xx....
.xx...
..xx..
...xx.
....x.
2
6 4</pre>



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



<h2 class="wp-block-heading">예제 출력 3</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="">......
......
......
......
..xx..
xx.xx.
.x..x.</pre>



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



<h2 class="wp-block-heading">예제 입력 A</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="">13 100
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
..................................................x................................................x
..................................................x................................................x
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
11 
1 1 1 1 1 1 1 1 1 1 1 </pre>



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



<h2 class="wp-block-heading">예제 출력 A</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="">....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
..................................................x................................................x
...................................................................................................x</pre>



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



<h2 class="wp-block-heading">예제 입력 B</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="">9 8
........
...xxx..
.xxx....
.x.x.xxx
.x.x...x
.x.xxx.x
.x.....x
.x.....x
.xxx...x
1
7</pre>



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



<h2 class="wp-block-heading">예제 출력 B</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="">........
........
...xxx..
.xxx.xxx
.x.x...x
.x.x...x
.x.xxx.x
.x.....x
.xxx...x</pre>



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



<h2 class="wp-block-heading">예제 입력 C</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 4
xxxx
xx.x
x..x
...x
1
3</pre>



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



<h2 class="wp-block-heading">예제 출력 C</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="">xxxx
.x.x
...x
x..x</pre>



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



<h2 class="wp-block-heading">예제 입력 D</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="">7 5
.....
.xxx.
.x...
xx.xx
x...x
x...x
x...x
1
4</pre>



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



<h2 class="wp-block-heading">예제 출력 D</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="">.....
.....
.xxx.
.x.xx
xx..x
x...x
x...x</pre>



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



<h2 class="wp-block-heading">예제 입력 E</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="">2 2
..
.x
1
2</pre>



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



<h2 class="wp-block-heading">예제 출력 E</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="">..
.x</pre>



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



<h2 class="wp-block-heading">예제 입력 F</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 5
xxxxx
x....
xxxxx
x....
x....
10 1 2 3 4 5 1 2 3 4 5</pre>



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



<h2 class="wp-block-heading">예제 출력 F</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="">.....
.....
.....
.xxxx
xxxx.</pre>



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



<h2 class="wp-block-heading">예제 입력 G</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="">10 10
xxxxxxxxxx
....x.....
...xxx....
.....x....
....xx....
.....x....
xxxxxx....
..x.......
.xxxx.....
...xxxxxxx
10 9 8 7 6 5 4 3 2 1 1</pre>



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



<h2 class="wp-block-heading">예제 출력 G</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="">..........
..........
..........
..........
..........
..........
xxxxxxxxxx
....xx....
xxxxxx....
.xxxxxxxx.</pre>



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



<h2 class="wp-block-heading">예제 입력 H</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 4
...x
..xx
.xxx
xxxx
10 1 2 3 4 1 2 3 4 3 4</pre>



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



<h2 class="wp-block-heading">예제 출력 H</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="">....
....
.xxx
..xx</pre>



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



<h2 class="wp-block-heading">예제 입력 I</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="">10 20
..xxxxxxxxxxxxxxx...
..x.............x...
..x.............x...
..x.............x...
..x.............x...
..x.............x...
..x.............x...
..xxxxxx........x...
................x...
x...............x...
2
1 7</pre>



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



<h2 class="wp-block-heading">예제 출력 I</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="">....................
..xxxxxxxxxxxxxxx...
..x.............x...
..x.............x...
..x.............x...
..x.............x...
..x.............x...
..x.............x...
..xxxxxx........x...
................x...</pre>



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



<h2 class="wp-block-heading">예제 입력 J</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="">9 8
........
.xxxx...
.x......
.x.xxxx.
.x....x.
.x....x.
.xxxx.x.
....xxx.
......x.
1
2</pre>



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



<h2 class="wp-block-heading">예제 출력 J</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="">........
........
.xxxx...
.x.xxxx.
.x....x.
.x....x.
.x....x.
.xxxxxx.
......x.</pre>



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



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



<p><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/25" target="_blank" rel="noreferrer noopener">Croatian Highschool Competitions in Informatics</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/29" target="_blank" rel="noreferrer noopener">2009</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/91" target="_blank" rel="noreferrer noopener">Croatian Regional Competition in Informatics 2009</a>&nbsp;5번</p>



<p><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/25" target="_blank" rel="noreferrer noopener">Croatian Highschool Competitions in Informatics</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/29" target="_blank" rel="noreferrer noopener">2009</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/1069" target="_blank" rel="noreferrer noopener">Regional Competition &#8211; Juniors</a>&nbsp;4번</p>



<ul class="wp-block-list">
<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/heize" target="_blank" rel="noreferrer noopener">heize</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/102" target="_blank" rel="noreferrer noopener">구현</a></li>



<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/141" 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)"/>



<figure class="wp-block-embed is-type-wp-embed is-provider-어제와-내일의-나-그-사이의-이야기 wp-block-embed-어제와-내일의-나-그-사이의-이야기"><div class="wp-block-embed__wrapper">
<blockquote class="wp-embedded-content" data-secret="EG4OUsUyN9"><a href="https://lycos7560.com/?p=2163">백준 2933번 (미네랄, C++, Simulation) / 추가 반례 [BAEKJOON]</a></blockquote><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  title="&#8220;백준 2933번 (미네랄, C++, Simulation) / 추가 반례 [BAEKJOON]&#8221; &#8212; 어제와 내일의 나 그 사이의 이야기" src="https://lycos7560.com/?p=2163&#038;embed=true#?secret=0JeHTukF6L#?secret=EG4OUsUyN9" data-secret="EG4OUsUyN9" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>



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



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



<p class="has-medium-font-size">나는 2933번을 해결할 때 공중에 있는 미네랄 리스트의  하단부를 전부 확인하는 방법으로 구현해서 다른 것이 없다.</p>



<p class="has-medium-font-size">골드 2 문제를 해결하니 골드 1을 같이 주네?? 개꿀 </p>



<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;list>
#include &lt;queue>

using namespace std;

// RC의 범위 최대값
constexpr int MAX = 101;

// 기본 맵
char map[MAX][MAX];

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

// BFS 사용할 Q
queue&lt;pair&lt;int, int>> myQ;

pair&lt;int, int> tempP;

// R 행, C 열, N 막대기를 던진 횟수
int R, C, N;

int dx, dy, dis;

int temp = 0;

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


list&lt;int> myList;
list&lt;int>::iterator it;

list&lt;pair&lt;int, int>> cList;
list&lt;pair&lt;int, int>>::iterator cit;

// true = left, false = right
bool check = false, leftRight = false;

void BFS(int x, int y)
{
	myQ.push(make_pair(x, y));

	while (!myQ.empty()) {
		tempP = myQ.front();
		myQ.pop();

		for (int i = 0; i &lt; 4; i++) {
			dy = tempP.second + dxdy[i][1];
			dx = tempP.first + dxdy[i][0];
			// 문제의 범위를 벗어나는 경우 => 넘어간다.
			if (dx &lt;= 0 || dy &lt;= 0 || dy > C || dx > R) continue;
			// 방문 처리가 되었거나 빈공간 => 넘어간다.
			if (mapCheck[dx][dy] == true || map[dx][dy] == '.') continue;
			mapCheck[dx][dy] = true;
			myQ.push(make_pair(dx, dy));
		}
	}
}

void CheckFloor() // 바닥을 체크합니다.
{
	for (int y = 1; y &lt;= C; y++) {
		// 바닥에 클러스터가 발견되고 방문처리가 되지 않았다면 
		if (map[1][y] == 'x' &amp;&amp; mapCheck[1][y] == false) {
			BFS(1, y); // BFS로 마킹
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	// 처음 맵을 초기화 해준다.
	for (int x = 1; x &lt; MAX; x++) {
		for (int y = 1; y &lt; MAX; y++) {
			map[x][y] = '.';
		}
	}

	cin >> R >> C;

	// 미네랄의 위치를 설정 (아래서 부터 시작)
	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cin >> map[x][y];
		}
	}

	cin >> N;

	/// 던진 횟수와 높이를 설정
	while (N > 0) {
		cin >> temp;
		myList.push_back(temp);
		N--;
	}

	// 던진 막대기 리스트를 순회합니다.
	for (it = myList.begin(); it != myList.end(); it++) {

		check = false; // 미네랄 부셔짐 체크 해제
		cList.clear(); // 공중의 미네랄 리스트 초기화

		// 해당 위치에 미네랄이 있는지 검색합니다.
		if (leftRight) { // 좌측 검색
			for (int y = C; y >= 1; y--) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;
				}
			}

			leftRight = !leftRight;
		}
		else { // 우측 검색
			for (int y = 1; y &lt;= C; y++) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;
				}
			}

			leftRight = !leftRight;
		}

		if (check) {  // 미네랄이 부셔졌다면
			// 공중에 있는 클러스트들을 리스트에 담는다.
			for (int x = R; x >= 1; x--) {
				for (int y = C; y >= 1; y--) {
					if (map[x][y] == 'x' &amp;&amp; mapCheck[x][y] == false) {
						cList.push_back(make_pair(x, y));
					}
				}
			}

			// 공중에 미네랄이 바닥과 연결될때까지 반복
			dis = 1;
			bool floor = true;
			while (floor) {

				if (cList.size() == 0) break;

				for (cit = cList.begin(); cit != cList.end(); cit++) {
					tempP.first = cit->first;
					tempP.second = cit->second;

					if (mapCheck[tempP.first - (dis + 1)][tempP.second] == true || tempP.first - (dis + 1) == 0) {
						floor = false;
						break;
					}
				}

				dis++;
			}

			if (!floor) {
				for (cit = cList.begin(); cit != cList.end(); cit++) {
					tempP.first = cit->first;
					tempP.second = cit->second;
					map[tempP.first][tempP.second] = '.';
				}

				for (cit = cList.begin(); cit != cList.end(); cit++) {
					tempP.first = cit->first;
					tempP.second = cit->second;
					map[tempP.first - (dis - 1)][tempP.second] = 'x';
				}	
			}

			// 방문 처리를 초기화 
			for (int x = R; x >= 1; x--) {
				for (int y = 1; y &lt;= C; y++) {
					mapCheck[x][y] = false;
				}
			}
		}
	}

	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cout &lt;&lt; map[x][y];
		}
		if (x == 1) break;
		cout &lt;&lt; "\n";
	}

	return 0;

}</pre>



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



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



<div style="height:100px" 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-18500%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-2-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5533/">백준 18500번 (미네랄 2, C++, Simulation) / 추가 반례 [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-18500%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-2-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5533/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2933번 (미네랄, C++, Simulation) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2933%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/2163/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2933%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/2163/#comments</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 25 Jan 2023 06:00:03 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[18500]]></category>
		<category><![CDATA[18500번]]></category>
		<category><![CDATA[2933]]></category>
		<category><![CDATA[2933번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cin.tie(NULL)]]></category>
		<category><![CDATA[cout.tie(NULL)]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false)]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></category>
		<category><![CDATA[simulation]]></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[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[리스트]]></category>
		<category><![CDATA[미네랄]]></category>
		<category><![CDATA[미네랄 2]]></category>
		<category><![CDATA[반례]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 2933]]></category>
		<category><![CDATA[백준 2933번]]></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[추가반례]]></category>
		<category><![CDATA[추가예제]]></category>
		<category><![CDATA[컴파일 에러]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[틀렸습니다]]></category>
		<category><![CDATA[틀렸습니다!]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=2163</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 2933번 '미네랄' 문제에 대한 글입니다. '그래프 Search'을 이용하여 해결하였습니다.<br />
추가적인 테스트 케이스를 제시합니다. (This is BAEKJOON's 2933 article on the 'Mineral' problem. I solved it using 'Graph Search'.<br />
Present additional test cases.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2933%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/2163/">백준 2933번 (미네랄, C++, Simulation) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:42px" 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>
<!-- 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"><a href="https://www.acmicpc.net/problem/2933" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/2933</a></p>



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



<figure id="problem-info" class="wp-block-table is-style-regular"><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">10752</td><td class="has-text-align-left" data-align="left">2935</td><td class="has-text-align-left" data-align="left">1917</td><td class="has-text-align-left" data-align="left">25.250%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">창영과 상근은 한 동굴을 놓고 소유권을 주장하고 있다. </p>



<p class="has-medium-font-size">두 사람은 막대기를 서로에게 던지는 방법을 이용해 누구의 소유 인지를 결정하기로 했다. <br><br>싸움은 동굴에서 벌어진다. 동굴에는 미네랄이 저장되어 있으며, 던진 막대기가 미네랄을 파괴할 수도 있다.</p>



<p class="has-medium-font-size">동굴은 R행 C열로 나타낼 수 있으며, R×C칸으로 이루어져 있다. </p>



<p class="has-medium-font-size">각 칸은 비어있거나 미네랄을 포함하고 있으며, 네 방향 중 하나로 인접한 미네랄이 포함된 두 칸은 같은 클러스터이다.</p>



<p class="has-medium-font-size">창영은 동굴의 왼쪽에 서있고, 상근은 오른쪽에 서있다. 두 사람은 턴을 번갈아가며 막대기를 던진다. </p>



<p class="has-medium-font-size">막대를 던지기 전에 던질 높이를 정해야 한다. 막대는 땅과 수평을 이루며 날아간다.</p>



<p class="has-medium-font-size">막대가 날아가다가 미네랄을 만나면, 그 칸에 있는 미네랄은 모두 파괴되고 막대는 그 자리에서 이동을 멈춘다.</p>



<p class="has-medium-font-size">미네랄이 파괴된 이후에 남은 클러스터가 분리될 수도 있다.  </p>



<p class="has-medium-font-size">새롭게 생성된 클러스터가 떠 있는 경우에는 중력에 의해서 바닥으로 떨어지게 된다. <br><br>떨어지는 동안 클러스터의 모양은 변하지 않는다. 클러스터는 다른 클러스터나 땅을 만나기 전까지 계속해서 떨어진다. <br><br>클러스터는 다른 클러스터 위에 떨어질 수 있고, 그 이후에는 합쳐지게 된다.</p>



<p class="has-medium-font-size">동굴에 있는 미네랄의 모양과 두 사람이 던진 막대의 높이가 주어진다. </p>



<p class="has-medium-font-size">모든 막대를 던지고 난 이후에 미네랄 모양을 구하는 프로그램을 작성하시오.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 동굴의 크기 R과 C가 주어진다. (1 ≤ R,C ≤ 100)</p>



<p class="has-medium-font-size">다음 R개 줄에는 C개의 문자가 주어지며, &#8216;.&#8217;는 빈 칸, &#8216;x&#8217;는 미네랄을 나타낸다.</p>



<p class="has-medium-font-size">다음 줄에는 막대를 던진 횟수 N이 주어진다. (1 ≤ N ≤ 100)</p>



<p class="has-medium-font-size">마지막 줄에는 막대를 던진 높이가 주어지며, 공백으로 구분되어져 있다. </p>



<p class="has-medium-font-size">모든 높이는 1과 R사이이며, 높이 1은 행렬의 가장 바닥, R은 가장 위를 의미한다. <br><br>첫 번째 막대는 왼쪽에서 오른쪽으로 던졌으며, 두 번째는 오른쪽에서 왼쪽으로, 이와 같은 식으로 번갈아가며 던진다.</p>



<p class="has-medium-font-size">공중에 떠 있는 미네랄 클러스터는 없으며, 두 개 또는 그 이상의 클러스터가 동시에 떨어지는 경우도 없다. </p>



<p class="has-medium-font-size">클러스터가 떨어질 때,&nbsp;그 클러스터 각 열의 맨 아래 부분 중 하나가 바닥 또는 미네랄 위로 떨어지는 입력만 주어진다.</p>



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



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



<p class="has-medium-font-size">입력 형식과 같은 형식으로 미네랄 모양을 출력한다.</p>



<div style="height:41px" 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 6
......
..xx..
..x...
..xx..
.xxxx.
1
3</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="">......
......
..xx..
..xx..
.xxxx.</pre>



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



<h2 class="wp-block-heading">예제 입력 2</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="">8 8
........
........
...x.xx.
...xxx..
..xxx...
..x.xxx.
..x...x.
.xxx..x.
5
6 6 4 3 1</pre>



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



<h2 class="wp-block-heading">예제 출력 2</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="">........
........
........
........
.....x..
..xxxx..
..xxx.x.
..xxxxx.</pre>



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



<h2 class="wp-block-heading">예제 입력 3</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="">7 6
......
......
xx....
.xx...
..xx..
...xx.
....x.
2
6 4</pre>



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



<h2 class="wp-block-heading">예제 출력 3</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="">......
......
......
......
..xx..
xx.xx.
.x..x.</pre>



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



<h2 class="wp-block-heading">예제 입력 A</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="">13 100
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
..................................................x................................................x
..................................................x................................................x
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
11 
1 1 1 1 1 1 1 1 1 1 1 </pre>



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



<h2 class="wp-block-heading">예제 출력 A</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="">....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
..................................................x................................................x
...................................................................................................x</pre>



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



<h2 class="wp-block-heading">예제 입력 B</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 4
xxxx
xx.x
x..x
...x
1
3</pre>



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



<h2 class="wp-block-heading">예제 출력 B</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="">xxxx
.x.x
...x
x..x</pre>



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



<h2 class="wp-block-heading">예제 입력 C</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="">2 2
..
.x
1
2</pre>



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



<h2 class="wp-block-heading">예제 출력 C</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="">..
.x</pre>



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



<h2 class="wp-block-heading">예제 입력 D</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 5
xxxxx
x....
xxxxx
x....
x....
10 1 2 3 4 5 1 2 3 4 5</pre>



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



<h2 class="wp-block-heading">예제 출력 D</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="">.....
.....
.....
.xxxx
xxxx.</pre>



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



<h2 class="wp-block-heading">예제 입력 E</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 4
...x
..xx
.xxx
xxxx
10 1 2 3 4 1 2 3 4 3 4</pre>



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



<h2 class="wp-block-heading">예제 출력 E</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="">....
....
.xxx
..xx</pre>



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



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



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



<li>잘못된 조건을 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</a></li>



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



<div style="height:33px" 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/102" target="_blank" rel="noreferrer noopener">구현</a></li>



<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/141" 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">첫째 줄에 동굴의 크기 R과 C (1 ≤ R,C ≤ 100)</p>



<p class="has-medium-font-size">다음 R개 줄에는 C개의 문자가 주어지며, &#8216;.&#8217;는 빈 칸, &#8216;x&#8217;는 미네랄을 나타낸다.</p>



<p class="has-medium-font-size">다음 줄에는 막대를 던진 횟수 N이 주어진다. (1 ≤ N ≤ 100)</p>



<p class="has-medium-font-size">모든 높이는 1과 R사이이며, 높이 1은 행렬의 가장 바닥, R은 가장 위를 의미한다.</p>



<p class="has-medium-font-size">공중에 떠 있는 미네랄 클러스터는 없으며, 두 개 또는 그 이상의 클러스터가 동시에 떨어지는 경우도 없다.</p>



<p class="has-medium-font-size"> 클러스터가 떨어질 때,&nbsp;그 클러스터 각 열의 맨 아래 부분 중 하나가 바닥 또는 미네랄 위로 떨어지는 입력만 주어진다.</p>



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



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



<p class="has-large-font-size">예제 1</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="650" height="438" src="https://lycos7560.com/wp-content/uploads/image-30.png" alt="" class="wp-image-2173" srcset="https://lycos7560.com/wp-content/uploads/image-30.png 650w, https://lycos7560.com/wp-content/uploads/image-30-300x202.png 300w" sizes="(max-width: 650px) 100vw, 650px" /></figure>



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



<p class="has-large-font-size">예제 2</p>



<figure class="wp-block-image size-full"><img decoding="async" width="1307" height="813" src="https://lycos7560.com/wp-content/uploads/image-32.png" alt="" class="wp-image-2177" srcset="https://lycos7560.com/wp-content/uploads/image-32.png 1307w, https://lycos7560.com/wp-content/uploads/image-32-300x187.png 300w, https://lycos7560.com/wp-content/uploads/image-32-768x478.png 768w" sizes="(max-width: 1307px) 100vw, 1307px" /></figure>



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



<p class="has-large-font-size">예제 3</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="788" height="553" src="https://lycos7560.com/wp-content/uploads/image-35.png" alt="" class="wp-image-2181" srcset="https://lycos7560.com/wp-content/uploads/image-35.png 788w, https://lycos7560.com/wp-content/uploads/image-35-300x211.png 300w, https://lycos7560.com/wp-content/uploads/image-35-768x539.png 768w" sizes="(max-width: 788px) 100vw, 788px" /></figure>



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



<p class="has-medium-font-size">이번에도 문제를 이해하는 것이 오래 걸렸다.. 일단 글을 읽으면 머리 속에서 잘 정리가 되지 않는다. </p>



<p class="has-medium-font-size">한 3~4 번을 다시 글을 읽은 후에야 어느 정도 이해를 하는 듯&#8230;.</p>



<p class="has-medium-font-size">일단 동굴을 코드로 구현해보자</p>



<div style="height:45px" 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;list>

using namespace std;

// RC의 범위 최대값
constexpr int MAX = 101;

// 기본 맵
char map[MAX][MAX];

// R 행, C 열, N 막대기를 던진 횟수
int R, C, N;

int temp = 0;


list&lt;int> myList;
list&lt;int>::iterator it;

bool debug = true;

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	// 처음 맵을 초기화 해준다.
	for (int x = 1; x &lt; MAX; x++) {
		for (int y = 1; y &lt; MAX; y++) {
			map[x][y] = '.';
		}
	}

	cin >> R >> C;

	// 미네랄의 위치를 설정 (아래서 부터 시작)
	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cin >> map[x][y];
		}
	}

	cin >> N;

	/// 던진 횟수와 높이를 설정
	while (N > 0){
		cin >> temp;
		myList.push_back(temp);
		N--;
	}

	if (debug) {
		for (int x = R; x >= 1; x--) {
			for (int y = 1; y &lt;= C; y++) {
				cout &lt;&lt; map[x][y] &lt;&lt; " ";
			}
			cout &lt;&lt; "\n";
		}
		cout &lt;&lt; "\n던진 막대기 높이 리스트\n";
		for (it = myList.begin(); it != myList.end(); it++) cout &lt;&lt; *it &lt;&lt; " ";
	}
	return 0;
}
</pre>



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



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



<p class="has-medium-font-size">다행히 생각대로 잘나온다.</p>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/image-1052.png" alt="" class="wp-image-5501" width="806" height="453" srcset="https://lycos7560.com/wp-content/uploads/image-1052.png 639w, https://lycos7560.com/wp-content/uploads/image-1052-300x169.png 300w" sizes="(max-width: 806px) 100vw, 806px" /></figure>



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



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



<p class="has-medium-font-size">이제 막대기를 던져서 해당 위치의 미네랄을 파괴하는 것까지 구현</p>



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

using namespace std;

// RC의 범위 최대값
constexpr int MAX = 101;

// 기본 맵
char map[MAX][MAX];

// R 행, C 열, N 막대기를 던진 횟수
int R, C, N;

int temp = 0;


list&lt;int> myList;
list&lt;int>::iterator it;

bool debug = true;

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	// 처음 맵을 초기화 해준다.
	for (int x = 1; x &lt; MAX; x++) {
		for (int y = 1; y &lt; MAX; y++) {
			map[x][y] = '.';
		}
	}

	cin >> R >> C;

	// 미네랄의 위치를 설정 (아래서 부터 시작)
	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cin >> map[x][y];
		}
	}

	cin >> N;

	/// 던진 횟수와 높이를 설정
	while (N > 0) {
		cin >> temp;
		myList.push_back(temp);
		N--;
	}

	// 던진 막대기 리스트를 순회합니다.
	for (it = myList.begin(); it != myList.end(); it++) {
		// 해당 위치에 미네랄이 있는지 검색합니다.
		// 일단은 좌->우 검색
		for (int x = 1; x &lt;= C; x++) {
			// 만약 미네랄이 있다면
			if (map[*it][x] == 'x') {
				cout &lt;&lt; "\n찾음\n";
				// 해당 미네랄을 빈 공간
				map[*it][x] = '.';
				break;
			}
		}
	}




	if (debug) {
		for (int x = R; x >= 1; x--) {
			for (int y = 1; y &lt;= C; y++) {
				cout &lt;&lt; map[x][y] &lt;&lt; " ";
			}
			cout &lt;&lt; "\n";
		}
		cout &lt;&lt; "\n던진 막대기 높이 리스트\n";
		for (it = myList.begin(); it != myList.end(); it++) cout &lt;&lt; *it &lt;&lt; " ";
	}
	return 0;
}
</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="719" height="557" src="https://lycos7560.com/wp-content/uploads/image-1053.png" alt="" class="wp-image-5505" srcset="https://lycos7560.com/wp-content/uploads/image-1053.png 719w, https://lycos7560.com/wp-content/uploads/image-1053-300x232.png 300w" sizes="(max-width: 719px) 100vw, 719px" /></figure>



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



<p class="has-medium-font-size">이제 좌/우에서 던지는 것을 구현해야 한다.</p>



<p class="has-medium-font-size">2가지 경우 좌/우 이므로 bool 값으로 체크해서 막대기를 던지는 것을 구현하였다.</p>



<div style="height:35px" 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;list>

using namespace std;

// RC의 범위 최대값
constexpr int MAX = 101;

// 기본 맵
char map[MAX][MAX];

// R 행, C 열, N 막대기를 던진 횟수
int R, C, N;

int temp = 0;


list&lt;int> myList;
list&lt;int>::iterator it;

// true = left, false = right
bool leftRight = true;

bool debug = true;

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	// 처음 맵을 초기화 해준다.
	for (int x = 1; x &lt; MAX; x++) {
		for (int y = 1; y &lt; MAX; y++) {
			map[x][y] = '.';
		}
	}

	cin >> R >> C;

	// 미네랄의 위치를 설정 (아래서 부터 시작)
	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cin >> map[x][y];
		}
	}

	cin >> N;

	/// 던진 횟수와 높이를 설정
	while (N > 0) {
		cin >> temp;
		myList.push_back(temp);
		N--;
	}

	// 던진 막대기 리스트를 순회합니다.
	for (it = myList.begin(); it != myList.end(); it++) {
		
		// 해당 위치에 미네랄이 있는지 검색합니다.
		// 일단은 좌->우 검색
		if (leftRight) { // 좌측 검색
			for (int y = 1; y &lt;= C; y++) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					cout &lt;&lt; "\n찾음\n";
					// 해당 미네랄을 빈 공간
					map[*it][y] = '.';
					break;
				}
			}
			leftRight = !leftRight;
		}
		else { // 우측 검색
			for (int y = C; y >= 1; y--) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					cout &lt;&lt; "\n찾음\n";
					// 해당 미네랄을 빈 공간
					map[*it][y] = '.';
					break;
				}
			}
			leftRight = !leftRight;
		}

	}

	if (debug) {
		for (int x = R; x >= 1; x--) {
			for (int y = 1; y &lt;= C; y++) {
				cout &lt;&lt; map[x][y] &lt;&lt; " ";
			}
			cout &lt;&lt; "\n";
		}
		cout &lt;&lt; "\n던진 막대기 높이 리스트\n";
		for (it = myList.begin(); it != myList.end(); it++) cout &lt;&lt; *it &lt;&lt; " ";
	}
	return 0;
}
</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="730" height="545" src="https://lycos7560.com/wp-content/uploads/image-1054.png" alt="" class="wp-image-5508" srcset="https://lycos7560.com/wp-content/uploads/image-1054.png 730w, https://lycos7560.com/wp-content/uploads/image-1054-300x224.png 300w" sizes="(max-width: 730px) 100vw, 730px" /></figure>



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



<p class="has-medium-font-size">생각대로 미네랄이 잘 파괴가 되는 것 같다.</p>



<p class="has-medium-font-size">이제 미네랄이 파괴 되었을 경우 여기서 말하는 클러스터(상하좌우가 연결된 미네랄 덩이)가 </p>



<p class="has-medium-font-size">공중에 떠있지 못하게 하기만 하면 끝일 것 같은데&#8230;. 방법이 문제다.</p>



<p class="has-medium-font-size">미네랄이 파괴되면 바닥과 연결된 미네랄을 모두 마킹해 주었다. </p>



<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;list>
#include &lt;queue>

using namespace std;

// RC의 범위 최대값
constexpr int MAX = 101;

// 기본 맵
char map[MAX][MAX];

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

// BFS 사용할 Q
queue&lt;pair&lt;int, int>> myQ;

pair&lt;int, int> tempP;

// R 행, C 열, N 막대기를 던진 횟수
int R, C, N;

int dx, dy;

int temp = 0;

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


list&lt;int> myList;
list&lt;int>::iterator it;

// true = left, false = right
bool check = false, leftRight = true;

bool debug = true;

void BFS(int x, int y)
{
	myQ.push(make_pair(x, y));

	while (!myQ.empty()) {
		tempP = myQ.front();
		myQ.pop();

		for (int i = 0; i &lt; 4; i++) {
			dy = tempP.second + dxdy[i][1];
			dx = tempP.first + dxdy[i][0];
			// 문제의 범위를 벗어나는 경우 => 넘어간다.
			if (dx &lt;= 0 || dy &lt;= 0 || dx > C || dy > R) continue;  // &lt;= 범위 틀림 기록용으로 남겨둠
			// 방문 처리가 되었거나 빈공간 => 넘어간다.
			if (mapCheck[dx][dy] == true || map[dx][dy] == '.') continue;
			mapCheck[dx][dy] = true;
			myQ.push(make_pair(dx, dy));
		}
	}

}

void CheckFloor() // 바닥을 체크합니다.
{
	for (int y = 1; y &lt;= C; y++) {
		// 바닥에 클러스터가 발견되고 방문처리가 되지 않았다면 
		if (map[1][y] == 'x' &amp;&amp; mapCheck[1][y] == false) {
			BFS(1, y); // BFS로 마킹
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	// 처음 맵을 초기화 해준다.
	for (int x = 1; x &lt; MAX; x++) {
		for (int y = 1; y &lt; MAX; y++) {
			map[x][y] = '.';
		}
	}

	cin >> R >> C;

	// 미네랄의 위치를 설정 (아래서 부터 시작)
	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cin >> map[x][y];
		}
	}

	cin >> N;

	/// 던진 횟수와 높이를 설정
	while (N > 0) {
		cin >> temp;
		myList.push_back(temp);
		N--;
	}

	// 던진 막대기 리스트를 순회합니다.
	for (it = myList.begin(); it != myList.end(); it++) {
		
		// 해당 위치에 미네랄이 있는지 검색합니다.
		// 일단은 좌->우 검색
		if (leftRight) { // 좌측 검색
			for (int y = 1; y &lt;= C; y++) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;

				}
			}

			leftRight = !leftRight;
		}
		else { // 우측 검색
			for (int y = C; y >= 1; y--) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;
				}
			}

			leftRight = !leftRight;
		}

		if (check) {  // 미네랄이 부셔졌다면 방문처리 초기화
			// 방문 처리를 초기화 
			for (int x = R; x >= 1; x--) {
				for (int y = 1; y &lt;= C; y++) {
					mapCheck[x][y] = false;
				}
			}
			check = false;
		}

	}

	if (debug) {

		for (int x = R; x >= 1; x--) {
			for (int y = 1; y &lt;= C; y++) {
				cout &lt;&lt; map[x][y] &lt;&lt; " ";
			}
			cout &lt;&lt; "\n";
		}
		cout &lt;&lt; "\n던진 막대기 높이 리스트\n";
		for (it = myList.begin(); it != myList.end(); it++) cout &lt;&lt; *it &lt;&lt; " ";
	}

	return 0;

}
</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="940" height="478" src="https://lycos7560.com/wp-content/uploads/image-41.png" alt="" class="wp-image-2190" srcset="https://lycos7560.com/wp-content/uploads/image-41.png 940w, https://lycos7560.com/wp-content/uploads/image-41-300x153.png 300w, https://lycos7560.com/wp-content/uploads/image-41-768x391.png 768w" sizes="(max-width: 940px) 100vw, 940px" /></figure>



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



<p class="has-medium-font-size">이제 공중에 있는 클러스터들의 좌표들을 저장하는 리스트를 만들고 확인</p>



<div style="height:27px" 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;list>
#include &lt;queue>

using namespace std;

// RC의 범위 최대값
constexpr int MAX = 101;

// 기본 맵
char map[MAX][MAX];

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

// BFS 사용할 Q
queue&lt;pair&lt;int, int>> myQ;

pair&lt;int, int> tempP;

// R 행, C 열, N 막대기를 던진 횟수
int R, C, N;

int dx, dy;

int temp = 0;

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


list&lt;int> myList;
list&lt;int>::iterator it;

list&lt;pair&lt;int, int>> cList;
list&lt;pair&lt;int, int>>::iterator cit;

// true = left, false = right
bool check = false, leftRight = true;

bool debug = true;

void BFS(int x, int y)
{
	myQ.push(make_pair(x, y));

	while (!myQ.empty()) {
		tempP = myQ.front();
		myQ.pop();

		for (int i = 0; i &lt; 4; i++) {
			dy = tempP.second + dxdy[i][1];
			dx = tempP.first + dxdy[i][0];
			// 문제의 범위를 벗어나는 경우 => 넘어간다.
			if (dx &lt;= 0 || dy &lt;= 0 || dx > C || dy > R) continue; // &lt;= 범위 틀림 기록용으로 남겨둠
			// 방문 처리가 되었거나 빈공간 => 넘어간다.
			if (mapCheck[dx][dy] == true || map[dx][dy] == '.') continue;
			mapCheck[dx][dy] = true;
			myQ.push(make_pair(dx, dy));
		}
	}

}

void CheckFloor() // 바닥을 체크합니다.
{
	for (int y = 1; y &lt;= C; y++) {
		// 바닥에 클러스터가 발견되고 방문처리가 되지 않았다면 
		if (map[1][y] == 'x' &amp;&amp; mapCheck[1][y] == false) {
			BFS(1, y); // BFS로 마킹
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	// 처음 맵을 초기화 해준다.
	for (int x = 1; x &lt; MAX; x++) {
		for (int y = 1; y &lt; MAX; y++) {
			map[x][y] = '.';
		}
	}

	cin >> R >> C;

	// 미네랄의 위치를 설정 (아래서 부터 시작)
	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cin >> map[x][y];
		}
	}

	cin >> N;

	/// 던진 횟수와 높이를 설정
	while (N > 0) {
		cin >> temp;
		myList.push_back(temp);
		N--;
	}

	// 던진 막대기 리스트를 순회합니다.
	for (it = myList.begin(); it != myList.end(); it++) {
		cList.clear();
		// 해당 위치에 미네랄이 있는지 검색합니다.
		// 일단은 좌->우 검색
		if (leftRight) { // 좌측 검색
			for (int y = 1; y &lt;= C; y++) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;

				}
			}

			leftRight = !leftRight;
		}
		else { // 우측 검색
			for (int y = C; y >= 1; y--) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;
				}
			}

			leftRight = !leftRight;
		}

		if (check) {  // 미네랄이 부셔졌다면

			for (int x = R; x >= 1; x--) {
				for (int y = 1; y &lt;= C; y++) {
					if (map[x][y] == 'x' &amp;&amp; mapCheck[x][y] == false) {
						cList.push_back(make_pair(x, y));
					}
				}
			}


			// 방문 처리를 초기화 
			for (int x = R; x >= 1; x--) {
				for (int y = 1; y &lt;= C; y++) {
					mapCheck[x][y] = false;
				}
			}
			check = false;
		}

	}

	if (debug) {

		for (int x = R; x >= 1; x--) {
			for (int y = 1; y &lt;= C; y++) {
				cout &lt;&lt; map[x][y] &lt;&lt; " ";
			}
			cout &lt;&lt; "\n";
		}
		cout &lt;&lt; "\n던진 막대기 높이 리스트\n";
		for (it = myList.begin(); it != myList.end(); it++) cout &lt;&lt; *it &lt;&lt; " ";
		cout &lt;&lt; "\n떠있는 클러스터 리스트 리스트\n";
		for (cit = cList.begin(); cit != cList.end(); cit++) cout &lt;&lt; " x : " &lt;&lt; cit->first &lt;&lt; " y : " &lt;&lt; cit->second &lt;&lt; "\n";
	}

	return 0;

}
</pre>



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



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/image-1055.png" alt="" class="wp-image-5514" width="859" height="593" srcset="https://lycos7560.com/wp-content/uploads/image-1055.png 786w, https://lycos7560.com/wp-content/uploads/image-1055-300x207.png 300w, https://lycos7560.com/wp-content/uploads/image-1055-768x531.png 768w" sizes="(max-width: 859px) 100vw, 859px" /></figure>



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



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



<p class="has-medium-font-size">미네랄이 파괴되면 바닥과 연결된 미네랄을 방문 처리해준다.</p>



<p class="has-medium-font-size">맵 전체에서 방문처리가 되지 않은 미네랄을 리스트에 담아준다</p>



<p class="has-medium-font-size">미네랄 리스트를 순회하면서 아래 부분이 방문 처리가 된 곳인지 확인한다. (내려갈 길이를 찾기 위함)</p>



<p class="has-medium-font-size">하단부가 방문처리가 되었다면 그 거리 -1 만큼 미네랄을 옮겨준다.</p>



<p class="has-medium-font-size">막대기의 수 만큼 위의 로직을 반복</p>



<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;list>
#include &lt;queue>

using namespace std;

// RC의 범위 최대값
constexpr int MAX = 101;

// 기본 맵
char map[MAX][MAX];

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

// BFS 사용할 Q
queue&lt;pair&lt;int, int>> myQ;

pair&lt;int, int> tempP;

// R 행, C 열, N 막대기를 던진 횟수
int R, C, N;

int dx, dy, dis;

int temp = 0;

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


list&lt;int> myList;
list&lt;int>::iterator it;

list&lt;pair&lt;int, int>> cList;
list&lt;pair&lt;int, int>>::iterator cit;

// true = left, false = right
bool check = false, leftRight = false;

void BFS(int x, int y)
{
	myQ.push(make_pair(x, y));

	while (!myQ.empty()) {
		tempP = myQ.front();
		myQ.pop();

		for (int i = 0; i &lt; 4; i++) {
			dy = tempP.second + dxdy[i][1];
			dx = tempP.first + dxdy[i][0];
			// 문제의 범위를 벗어나는 경우 => 넘어간다.
			if (dx &lt;= 0 || dy &lt;= 0 || dy > C || dx > R) continue;
			// 방문 처리가 되었거나 빈공간 => 넘어간다.
			if (mapCheck[dx][dy] == true || map[dx][dy] == '.') continue;
			mapCheck[dx][dy] = true;
			myQ.push(make_pair(dx, dy));
		}
	}
}

void CheckFloor() // 바닥을 체크합니다.
{
	for (int y = 1; y &lt;= C; y++) {
		// 바닥에 클러스터가 발견되고 방문처리가 되지 않았다면 
		if (map[1][y] == 'x' &amp;&amp; mapCheck[1][y] == false) {
			BFS(1, y); // BFS로 마킹
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	// 처음 맵을 초기화 해준다.
	for (int x = 1; x &lt; MAX; x++) {
		for (int y = 1; y &lt; MAX; y++) {
			map[x][y] = '.';
		}
	}

	cin >> R >> C;

	// 미네랄의 위치를 설정 (아래서 부터 시작)
	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cin >> map[x][y];
		}
	}

	cin >> N;

	/// 던진 횟수와 높이를 설정
	while (N > 0) {
		cin >> temp;
		myList.push_back(temp);
		N--;
	}

	// 던진 막대기 리스트를 순회합니다.
	for (it = myList.begin(); it != myList.end(); it++) {

		check = false; // 미네랄 부셔짐 체크 해제
		cList.clear(); // 공중의 미네랄 리스트 초기화

		// 해당 위치에 미네랄이 있는지 검색합니다.
		if (leftRight) { // 좌측 검색
			for (int y = C; y >= 1; y--) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;
				}
			}

			leftRight = !leftRight;
		}
		else { // 우측 검색
			for (int y = 1; y &lt;= C; y++) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;
				}
			}

			leftRight = !leftRight;
		}

		if (check) {  // 미네랄이 부셔졌다면
			// 공중에 있는 클러스트들을 리스트에 담는다.
			for (int x = R; x >= 1; x--) {
				for (int y = C; y >= 1; y--) {
					if (map[x][y] == 'x' &amp;&amp; mapCheck[x][y] == false) {
						cList.push_back(make_pair(x, y));
					}
				}
			}

			// 공중에 미네랄이 바닥과 연결될때까지 반복
			dis = 1;
			bool floor = true;
			while (floor) {

				if (cList.size() == 0) break;

				for (cit = cList.begin(); cit != cList.end(); cit++) {
					tempP.first = cit->first;
					tempP.second = cit->second;

					if (mapCheck[tempP.first - (dis + 1)][tempP.second] == true || tempP.first - (dis + 1) == 0) {
						floor = false;
						break;
					}
				}

				dis++;
			}

			if (!floor) {
				for (cit = cList.begin(); cit != cList.end(); cit++) {
					tempP.first = cit->first;
					tempP.second = cit->second;
					map[tempP.first][tempP.second] = '.';
				}

				for (cit = cList.begin(); cit != cList.end(); cit++) {
					tempP.first = cit->first;
					tempP.second = cit->second;
					map[tempP.first - (dis - 1)][tempP.second] = 'x';
				}	
			}

			// 방문 처리를 초기화 
			for (int x = R; x >= 1; x--) {
				for (int y = 1; y &lt;= C; y++) {
					mapCheck[x][y] = false;
				}
			}
		}
	}

	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cout &lt;&lt; map[x][y];
		}
		if (x == 1) break;
		cout &lt;&lt; "\n";
	}

	return 0;

}
</pre>



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



<p class="has-medium-font-size"><strong>계속 틀린 원인은 바닥과 연결된 클러스터를 찾는 BFS 탐색에서 R과 C의 범위를 바꾸어 탐색</strong></p>



<p class="has-medium-font-size">이 부분 하나로 엄청난 시간을 낭비</p>



<p class="has-medium-font-size">웃긴 부분은 다른 테스트 케이스는 다 잘돌아감 ㅋㅋ </p>



<p>구현이 조금 빡센 문제&#8230;</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1038" height="847" src="https://lycos7560.com/wp-content/uploads/image-1056.png" alt="" class="wp-image-5516" srcset="https://lycos7560.com/wp-content/uploads/image-1056.png 1038w, https://lycos7560.com/wp-content/uploads/image-1056-300x245.png 300w, https://lycos7560.com/wp-content/uploads/image-1056-768x627.png 768w" sizes="(max-width: 1038px) 100vw, 1038px" /></figure>



<figure class="wp-block-image size-full"><img decoding="async" width="1039" height="453" src="https://lycos7560.com/wp-content/uploads/image-1057.png" alt="" class="wp-image-5517" srcset="https://lycos7560.com/wp-content/uploads/image-1057.png 1039w, https://lycos7560.com/wp-content/uploads/image-1057-300x131.png 300w, https://lycos7560.com/wp-content/uploads/image-1057-768x335.png 768w" sizes="(max-width: 1039px) 100vw, 1039px" /></figure>



<div style="height:50px" 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-2933%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/2163/">백준 2933번 (미네랄, C++, Simulation) / 추가 반례 [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-2933%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/2163/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1966번 (프린터 큐, C++, queue) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/1966-printer-queue-c-queue-baekjoon/4522/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/1966-printer-queue-c-queue-baekjoon/4522/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 13 Jan 2023 18:11:08 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1966]]></category>
		<category><![CDATA[1966번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1966]]></category>
		<category><![CDATA[백준 1966번]]></category>
		<category><![CDATA[시뮬레이션]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[자료구조]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[큐]]></category>
		<category><![CDATA[프린터 큐]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=4522</guid>

					<description><![CDATA[<p>백준 1966번 "프린터 큐" 문제에 대한 글입니다.  자료구조 "Queue"를 이용하여 해결하였습니다. (This is an article about the "Printer Queue" problem in Baekjun 1966. I solved it using the data structure "Queue".)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/1966-printer-queue-c-queue-baekjoon/4522/">백준 1966번 (프린터 큐, C++, queue) [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:68px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">프린터 큐</h1>



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



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



<figure id="problem-info" class="wp-block-table"><table><thead><tr><th>시간 제한</th><th>메모리 제한</th><th>제출</th><th>정답</th><th>맞힌 사람</th><th>정답 비율</th></tr></thead><tbody><tr><td>2 초</td><td>128 MB</td><td>55389</td><td>31374</td><td>24821</td><td>57.762%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">여러분도 알다시피 여러분의 프린터 기기는 여러분이 인쇄하고자 하는 문서를 인쇄 명령을 받은 ‘순서대로’, </p>



<p class="has-medium-font-size">즉 먼저 요청된 것을 먼저 인쇄한다. </p>



<p class="has-medium-font-size">여러 개의 문서가 쌓인다면 Queue 자료구조에 쌓여서 FIFO &#8211; First In First Out &#8211; 에 따라 인쇄가 되게 된다. </p>



<p class="has-medium-font-size">하지만 상근이는 새로운 프린터기 내부 소프트웨어를 개발하였는데, </p>



<p class="has-medium-font-size">이 프린터기는 다음과 같은 조건에 따라 인쇄를 하게 된다.</p>



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



<p class="has-medium-font-size">1. 현재 Queue의 가장 앞에 있는 문서의 ‘중요도’를 확인한다.</p>



<p class="has-medium-font-size">2. 나머지 문서들 중 현재 문서보다 중요도가 높은 문서가 하나라도 있다면, </p>



<p class="has-medium-font-size">이 문서를 인쇄하지 않고 Queue의 가장 뒤에 재배치 한다. </p>



<p class="has-medium-font-size">그렇지 않다면 바로 인쇄를 한다.</p>



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



<p class="has-medium-font-size">예를 들어 Queue에 4개의 문서(A B C D)가 있고, </p>



<p class="has-medium-font-size">중요도가 2 1 4 3 라면 C를 인쇄하고, 다음으로 D를 인쇄하고 A, B를 인쇄하게 된다.</p>



<p class="has-medium-font-size">여러분이 할 일은, 현재 Queue에 있는 문서의 수와 중요도가 주어졌을 때, </p>



<p class="has-medium-font-size">어떤 한 문서가 몇 번째로 인쇄되는지 알아내는 것이다. </p>



<p class="has-medium-font-size">예를 들어 위의 예에서 C문서는 1번째로, A문서는 3번째로 인쇄되게 된다.</p>



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



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



<p class="has-medium-font-size">첫 줄에 테스트 케이스의 수가 주어진다. </p>



<p class="has-medium-font-size">각 테스트 케이스는 두 줄로 이루어져 있다.</p>



<p class="has-medium-font-size">테스트 케이스의 첫 번째 줄에는 문서의 개수 N(1 ≤ N ≤ 100)과, </p>



<p class="has-medium-font-size">몇 번째로 인쇄되었는지 궁금한 문서가 현재 Queue에서 몇 번째에 놓여 있는지를 나타내는 정수 M(0 ≤ M &lt; N)이 주어진다. </p>



<p class="has-medium-font-size">이때 맨 왼쪽은 0번째라고 하자. 두 번째 줄에는 N개 문서의 중요도가 차례대로 주어진다. </p>



<p class="has-medium-font-size">중요도는 1 이상 9 이하의 정수이고, 중요도가 같은 문서가 여러 개 있을 수도 있다.</p>



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



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



<p class="has-medium-font-size">각 테스트 케이스에 대해 문서가 몇 번째로 인쇄되는지 출력한다.</p>



<div style="height:44px" 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="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">3
1 0
5
4 2
1 2 3 4
6 0
1 1 9 1 1 1</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="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1
2
5</pre>



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



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



<p><a href="https://www.acmicpc.net/category/1" target="_blank" rel="noreferrer noopener">ICPC</a> > <a href="https://www.acmicpc.net/category/7" target="_blank" rel="noreferrer noopener">Regionals</a> > <a href="https://www.acmicpc.net/category/10" target="_blank" rel="noreferrer noopener">Europe</a> > <a href="https://www.acmicpc.net/category/15" target="_blank" rel="noreferrer noopener">Northwestern European Regional Contest</a> > <a href="https://www.acmicpc.net/category/detail/55" target="_blank" rel="noreferrer noopener">NWERC 2006</a> F번</p>



<ul class="wp-block-list">
<li>문제의 오타를 찾은 사람: <a href="https://www.acmicpc.net/user/doju" target="_blank" rel="noreferrer noopener">doju</a></li>



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



<div style="height:36px" 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/102" target="_blank" rel="noreferrer noopener">구현</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/175" target="_blank" rel="noreferrer noopener">자료 구조</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/141" target="_blank" rel="noreferrer noopener">시뮬레이션</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/72" target="_blank" rel="noreferrer noopener">큐</a></li>
</ul>



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



<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)"/>



<figure class="wp-block-image size-full"><img decoding="async" width="1600" height="700" src="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230114_030510754.jpg" alt="" class="wp-image-4525" srcset="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230114_030510754.jpg 1600w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230114_030510754-300x131.jpg 300w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230114_030510754-768x336.jpg 768w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230114_030510754-1536x672.jpg 1536w" sizes="(max-width: 1600px) 100vw, 1600px" /></figure>



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



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



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



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

using namespace std;

queue&lt;pair&lt;int, bool>> myQueue; // 프린터 Q
list &lt;int> resList; // 결과를 저장하는 리스트

pair&lt;int, bool> tempPair;

int N, temp , number, target, cnt;

int arr[10]; // [i] i의 중요도를 가진 문서의 개수를 저장 

int main()
{
	cin >> N;
	while (N-- > 0) {
		
		// 초기화
		for (int i = 1; i &lt;= 9; i++) arr[i] = 0;
		while (!myQueue.empty()) myQueue.pop();
		cnt = 1;

		cin >> number >> target;

		for (int i = 0; i &lt; number; i++) {

			cin >> temp;
			arr[temp]++;

			// 목표의 문서를 마킹
			if (target == i) tempPair = make_pair(temp, true);
			else tempPair = make_pair(temp, false);

			myQueue.push(tempPair);
		}

		for (int i = 9; i >= 1; i--) {
			while (arr[i] != 0) { // 상위 중요도 문서부터 문서 개수가 0 이될때까지 실행
				tempPair = myQueue.front();

				if (tempPair.first != i) {
					myQueue.pop();
					myQueue.push(tempPair);
				}
				else 
				{	// 만약 목표로하는 문서일 경우 (마킹된 문서)
					if (tempPair.second == true) {
						resList.push_back(cnt); // 인쇄된 순서를 결과에 저장 
						myQueue.pop();
						arr[i]--;
					}
					else
					{
						arr[i]--;
						cnt++;
						myQueue.pop();
					}
				}
			}
		}
	}

	for (auto it = resList.begin(); it != resList.end(); it++) {
		cout &lt;&lt; *it &lt;&lt; " ";
	}

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1037" height="98" src="https://lycos7560.com/wp-content/uploads/image-935.png" alt="" class="wp-image-4523" srcset="https://lycos7560.com/wp-content/uploads/image-935.png 1037w, https://lycos7560.com/wp-content/uploads/image-935-300x28.png 300w, https://lycos7560.com/wp-content/uploads/image-935-768x73.png 768w" sizes="(max-width: 1037px) 100vw, 1037px" /></figure>



<div style="height:38px" 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/1966-printer-queue-c-queue-baekjoon/4522/">백준 1966번 (프린터 큐, C++, queue) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/1966-printer-queue-c-queue-baekjoon/4522/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1157번 (단어 공부, C++, 문자열) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/1157-study-words-c-baekjoon/4183/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/1157-study-words-c-baekjoon/4183/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sat, 07 Jan 2023 18:58:50 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1157]]></category>
		<category><![CDATA[1157번]]></category>
		<category><![CDATA[American Standard Code for Information Interchange]]></category>
		<category><![CDATA[ASCII]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[string]]></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[백준 1157]]></category>
		<category><![CDATA[백준 1157번]]></category>
		<category><![CDATA[시뮬레이션]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=4183</guid>

					<description><![CDATA[<p>This is an article about the question of 'study words' in BAEKJOON 1157. To solve the problem, you need to know 'ASCII'.</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/1157-study-words-c-baekjoon/4183/">백준 1157번 (단어 공부, C++, 문자열) [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:68px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">단어 공부</h1>



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



<div style="height:39px" 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">2 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">204015</td><td class="has-text-align-left" data-align="left">80913</td><td class="has-text-align-left" data-align="left">64291</td><td class="has-text-align-left" data-align="left">39.417%</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">알파벳 대소문자로 된 단어가 주어지면, </p>



<p class="has-medium-font-size">이 단어에서 가장 많이 사용된 알파벳이 무엇인지 알아내는 프로그램을 작성하시오. </p>



<p class="has-medium-font-size">단, 대문자와 소문자를 구분하지 않는다.</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">첫째 줄에 알파벳 대소문자로 이루어진 단어가 주어진다. </p>



<p class="has-medium-font-size">주어지는 단어의 길이는 1,000,000을 넘지 않는다.</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">첫째 줄에 이 단어에서 가장 많이 사용된 알파벳을 대문자로 출력한다. </p>



<p class="has-medium-font-size">단, 가장 많이 사용된 알파벳이 여러 개 존재하는 경우에는 ?를 출력한다.</p>



<div style="height:54px" 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="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Mississipi</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="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">?</pre>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<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/user/author5" target="_blank" rel="noreferrer noopener">author5</a></li>



<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</a>, <a href="https://www.acmicpc.net/user/rnjs4197">rn</a><a href="https://www.acmicpc.net/user/rnjs4197" target="_blank" rel="noreferrer noopener">j</a><a href="https://www.acmicpc.net/user/rnjs4197">s4197</a></li>
</ul>



<div style="height:55px" 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/102" target="_blank" rel="noreferrer noopener">구현</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/158" target="_blank" rel="noreferrer noopener">문자열</a></li>
</ul>



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



<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">이 문제를 해결하려면 ASCII 코드에 대해서 알아야 한다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1579" height="942" src="https://lycos7560.com/wp-content/uploads/image-863.png" alt="" class="wp-image-4187" srcset="https://lycos7560.com/wp-content/uploads/image-863.png 1579w, https://lycos7560.com/wp-content/uploads/image-863-300x179.png 300w, https://lycos7560.com/wp-content/uploads/image-863-768x458.png 768w, https://lycos7560.com/wp-content/uploads/image-863-1536x916.png 1536w" sizes="(max-width: 1579px) 100vw, 1579px" /></figure>



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



<figure class="wp-block-embed is-type-wp-embed is-provider-어제와-내일의-나-그-사이의-이야기 wp-block-embed-어제와-내일의-나-그-사이의-이야기"><div class="wp-block-embed__wrapper">
<blockquote class="wp-embedded-content" data-secret="CKW4Pk2NOM"><a href="https://lycos7560.com/?p=4186">ASCII Table &#8211; American Standard Code for Information Interchange Table</a></blockquote><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  title="&#8220;ASCII Table &#8211; American Standard Code for Information Interchange Table&#8221; &#8212; 어제와 내일의 나 그 사이의 이야기" src="https://lycos7560.com/?p=4186&#038;embed=true#?secret=7VqyWfia3N#?secret=CKW4Pk2NOM" data-secret="CKW4Pk2NOM" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>



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



<p class="has-medium-font-size">알파벳의 개수 26만큼 배열을 선언한다. (배열의 값은 해당 알파벳의 개수)</p>



<p class="has-medium-font-size">문제의 문자열을 인덱스로 순회하면서 대문자/소문자에 관계없이 알파벳 배열에 개수를 추가한다.</p>



<p class="has-medium-font-size">인덱스를 순회하며 가장 큰 값을 찾고</p>



<p class="has-medium-font-size">배열을 오름차순으로 정렬한 뒤에 0번과 1번 인덱스를 비교한다.</p>



<p class="has-medium-font-size">만약 값이 같다면 최대 개수가 같은 알파벳이 있다는 뜻으로 ? 를 출력한다. </p>



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



<p class="has-medium-font-size">문제의 포인트는 대문자/소문자에 관계없이 알파벳의 개수를 체크,</p>



<p class="has-medium-font-size">가장 많은 알파벳 찾을 찾아 출력하기,</p>



<p class="has-medium-font-size">최댓값 중복에 대한 예외 처리 인 것 같다.</p>



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



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



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



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

using namespace std;

string str;

int arr[26]; // 알파벳의 개수는 26개

int main()
{
	// 문제의 문자열을 받는다.
	cin >> str;

	for (int i = 0; i &lt; str.length(); i++) {
		if (str[i] >= 97) 	arr[(str[i] - 32) - 'A']++; // 소문자
		else arr[str[i] - 'A']++; // 대문자
	}

	// 가장 많이 사용한 알파벳을 찾는다.
	int maxIndex = -1;
	int max = -1;
	for (int i = 0; i &lt; 26; i++) {
		if (max &lt; arr[i]) {
			max = arr[i];
			maxIndex = i;
		}
	}

	// 가장많이 사용한 알파벳을 출력한다.
	sort(arr, arr + 26, greater&lt;int>()); // 내림차순 정렬

	// 0번과 1번이 같다면 가장 많이 사용된 알파벳이 한개가 아니라는 의미 
	if (arr[0] == arr[1]) {
		cout &lt;&lt; "?"; 
	}
	else { 
		char ch = maxIndex + 'A'; 
		cout &lt;&lt; ch;
	} 

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1042" height="100" src="https://lycos7560.com/wp-content/uploads/image-862.png" alt="" class="wp-image-4185" srcset="https://lycos7560.com/wp-content/uploads/image-862.png 1042w, https://lycos7560.com/wp-content/uploads/image-862-300x29.png 300w, https://lycos7560.com/wp-content/uploads/image-862-768x74.png 768w" sizes="(max-width: 1042px) 100vw, 1042px" /></figure>



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



<p class="has-medium-font-size">문제를 풀고 다른 사람들이 작성한 코드를 보니 ASCII 코드를 사용하는 방법은 아래가 더 좋은 것 같다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="548" height="151" src="https://lycos7560.com/wp-content/uploads/image-865.png" alt="" class="wp-image-4193" srcset="https://lycos7560.com/wp-content/uploads/image-865.png 548w, https://lycos7560.com/wp-content/uploads/image-865-300x83.png 300w" sizes="(max-width: 548px) 100vw, 548px" /></figure>



<p><a href="https://rujang.tistory.com/entry/%EB%B0%B1%EC%A4%80-1157%EB%B2%88-%EB%8B%A8%EC%96%B4-%EA%B3%B5%EB%B6%80-C" target="_blank" rel="noreferrer noopener">https://rujang.tistory.com/entry/%EB%B0%B1%EC%A4%80-1157%EB%B2%88-%EB%8B%A8%EC%96%B4-%EA%B3%B5%EB%B6%80-C</a></p>



<div style="height:54px" 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/1157-study-words-c-baekjoon/4183/">백준 1157번 (단어 공부, C++, 문자열) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/1157-study-words-c-baekjoon/4183/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2920번 (음계, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/2920-tune-scale-c-baekjoon/4178/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/2920-tune-scale-c-baekjoon/4178/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sat, 07 Jan 2023 17:40:15 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2920]]></category>
		<category><![CDATA[2920번]]></category>
		<category><![CDATA[ascending]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[descending]]></category>
		<category><![CDATA[mixed]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 2920]]></category>
		<category><![CDATA[백준 2920번]]></category>
		<category><![CDATA[시뮬레이션]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[음계]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=4178</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 2920번 '음계' 문제에 대한 글입니다. 인덱스와 값의 관계로 오름차순과 내림차순을 구별하여 해결하였습니다. (This is an article on the 'tune scale' problem in BAEKJOON 2920. Due to the relationship between the index and the value, the ascending and descending order were distinguished and resolved.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/2920-tune-scale-c-baekjoon/4178/">백준 2920번 (음계, C++) [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:40px" aria-hidden="true" class="wp-block-spacer"></div>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-5681cdfe      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#음계" class="uagb-toc-link__trigger">음계</a><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">음계</h1>



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



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



<figure id="problem-info" class="wp-block-table"><table><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">80097</td><td class="has-text-align-left" data-align="left">43633</td><td class="has-text-align-left" data-align="left">37621</td><td class="has-text-align-left" data-align="left">55.702%</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">다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. </p>



<p class="has-medium-font-size">이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. </p>



<p class="has-medium-font-size">c는 1로, d는 2로, &#8230;, C를 8로 바꾼다.</p>



<p class="has-medium-font-size">1부터 8까지 차례대로 연주한다면 ascending, </p>



<p class="has-medium-font-size">8부터 1까지 차례대로 연주한다면 descending, </p>



<p class="has-medium-font-size">둘 다 아니라면 mixed 이다.</p>



<p class="has-medium-font-size">연주한 순서가 주어졌을 때, </p>



<p class="has-medium-font-size">이것이 ascending인지, descending인지, 아니면 mixed인지 판별하는 프로그램을 작성하시오.</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">첫째 줄에 8개 숫자가 주어진다. </p>



<p class="has-medium-font-size">이 숫자는 문제 설명에서 설명한 음이며, 1부터 8까지 숫자가 한 번씩 등장한다.</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">첫째 줄에 ascending, descending, mixed 중 하나를 출력한다.</p>



<div style="height:50px" 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="">1 2 3 4 5 6 7 8</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="">ascending</pre>



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



<h2 class="wp-block-heading">예제 입력 2</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="">8 7 6 5 4 3 2 1</pre>



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



<h2 class="wp-block-heading">예제 출력 2</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="">descending</pre>



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



<h2 class="wp-block-heading">예제 입력 3</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="">8 1 7 2 6 3 5 4</pre>



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



<h2 class="wp-block-heading">예제 출력 3</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="">mixed</pre>



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



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



<p><a href="https://www.acmicpc.net/category/45" target="_blank" rel="noreferrer noopener">Contest</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/17" target="_blank" rel="noreferrer noopener">Croatian Open Competition in Informatics</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/21" target="_blank" rel="noreferrer noopener">COCI 2009/2010</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/83" target="_blank" rel="noreferrer noopener">Contest #1</a>&nbsp;1번</p>



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



<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</a></li>



<li>문제의 오타를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/thinksong1" target="_blank" rel="noreferrer noopener">thinksong1</a></li>
</ul>



<div style="height:58px" 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/102" 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">ascending, descending 를 어떤 방법으로 구별하는 지가 이 문제의 포인트 같다.</p>



<p class="has-medium-font-size">나는 숫자들을 배열에 넣어서 ( arr[i] ) 배열의 인덱스와 수의 관계로 구별했다.</p>



<p class="has-medium-font-size">만약 오름차순이라면</p>



<p class="has-medium-font-size">arr[0] = 1, arr[1] = 2, arr[2] = 3 &#8230;  arr[7] = 8  <strong>값과 인덱스의 차이가 1</strong>이다.</p>



<p class="has-medium-font-size">만약 내림차순이라면</p>



<p class="has-medium-font-size">arr[0] = 8, arr[1] = 7, arr[2] = 6 &#8230;  arr[7] = 1  <strong>값과 인덱스의 합이 8</strong>이다.</p>



<p class="has-medium-font-size">ascending가 아니면 descending를 확인 </p>



<p class="has-medium-font-size">descending가 아니면 Mixed의 인덱스로 보내어 답을 구하였다.</p>



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



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



<div style="height:38px" 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>

using namespace std;

int arr[8];
string str[3] = { "ascending", "descending", "mixed" };

int main()
{
	// 8개의 숫자를 차례대로 입력받는다.
	for (int i = 0; i &lt; 8; i++) {
		cin >> arr[i];
	}

	int cnt = 0;

	for (int i = 0; i &lt; 8; i++) {

		switch (cnt)
		{	
			case 0: // 처음은 오름차순을 체크
				if (arr[i] - i == 1) { continue; } // 오름차순은 arr[i] - i == 1 로 판단 가능
				else if (arr[i] + i == 8) { cnt++; } // 내름차순은 arr[i] + i == 8 로 판단 가능
				else { cnt = 2; }
				break;

			case 1:
				if (arr[i] + i == 8) { continue; } // 내름차순은 arr[i] + i == 8 로 판단 가능
				else { cnt = 2; }
				break;

			default:
				break;
		}

	}

	cout &lt;&lt; str[cnt];
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1034" height="102" src="https://lycos7560.com/wp-content/uploads/image-861.png" alt="" class="wp-image-4180" srcset="https://lycos7560.com/wp-content/uploads/image-861.png 1034w, https://lycos7560.com/wp-content/uploads/image-861-300x30.png 300w, https://lycos7560.com/wp-content/uploads/image-861-768x76.png 768w" sizes="(max-width: 1034px) 100vw, 1034px" /></figure>



<div style="height:39px" 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/2920-tune-scale-c-baekjoon/4178/">백준 2920번 (음계, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/2920-tune-scale-c-baekjoon/4178/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
