<?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%9E%AC%EA%B7%80/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Thu, 17 Oct 2024 10:19:12 +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>백준 16953번 (A → B, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-16953%eb%b2%88-a-%e2%86%92-b-c-baekjoon/38376/</link>
					<comments>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-16953%eb%b2%88-a-%e2%86%92-b-c-baekjoon/38376/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 17 Oct 2024 08:40:22 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[16953번]]></category>
		<category><![CDATA[A → B]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Recursive]]></category>
		<category><![CDATA[그래프]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[그리디 알고리즘]]></category>
		<category><![CDATA[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 16953번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[재귀]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=38376</guid>

					<description><![CDATA[<p>A → B https://www.acmicpc.net/problem/16953 시간 제한 메모리 제한 제출 정답 맞힌 사람 정답 비율 2 초 512 MB 61243 25275 19996 39.758% 문제 정수 A를 B로 바꾸려고 한다. 가능한 연산은 다음과 같은 두 가지이다. A를 B로 바꾸는데 필요한 연산의 최솟값을 구해보자. 입력 첫째 줄에 A, B (1 ≤ A &#60; B ≤ 109)가 주어진다. 출력 [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-16953%eb%b2%88-a-%e2%86%92-b-c-baekjoon/38376/">백준 16953번 (A → B, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h1 class="wp-block-heading">A → B <img decoding="async" width="30" height="38" class="wp-image-37910" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Sliver_2.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Sliver_2.jpg 400w, https://lycos7560.com/wp-content/uploads/2024/03/Sliver_2-234x300.jpg 234w" sizes="(max-width: 30px) 100vw, 30px" /></h1>



<p><a href="https://www.acmicpc.net/problem/16953" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/16953</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">2 초</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">61243</td><td class="has-text-align-left" data-align="left">25275</td><td class="has-text-align-left" data-align="left">19996</td><td class="has-text-align-left" data-align="left">39.758%</td></tr></tbody></table></figure>



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



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



<p>정수 A를 B로 바꾸려고 한다. 가능한 연산은 다음과 같은 두 가지이다.</p>



<ul class="wp-block-list">
<li>2를 곱한다.</li>



<li>1을 수의 가장 오른쪽에 추가한다.&nbsp;</li>
</ul>



<p>A를 B로 바꾸는데 필요한 연산의 최솟값을 구해보자.</p>



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



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



<p>첫째 줄에 A, B (1 ≤ A &lt; B ≤ 10<sup>9</sup>)가 주어진다.</p>



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



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



<p>A를 B로 바꾸는데 필요한 연산의 최솟값에 1을 더한 값을 출력한다. </p>



<p>만들 수 없는 경우에는 -1을 출력한다.</p>



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



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



<div class="wp-block-uagb-container uagb-block-ecb9f492 alignfull uagb-is-root-container"><div class="uagb-container-inner-blocks-wrap">
<div class="wp-block-uagb-container uagb-block-5a2a4110">
<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 162</pre>
</div>



<div class="wp-block-uagb-container uagb-block-99e5d95d">
<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</pre>
</div>
</div></div>



<p>2&nbsp;→ 4&nbsp;→ 8&nbsp;→ 81&nbsp;→ 162</p>



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



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



<div class="wp-block-uagb-container uagb-block-1a4486a4 alignfull uagb-is-root-container"><div class="uagb-container-inner-blocks-wrap">
<div class="wp-block-uagb-container uagb-block-edc25381">
<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 42</pre>
</div>



<div class="wp-block-uagb-container uagb-block-7c5a70a3">
<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>
</div></div>



<p>2&nbsp;→ 4&nbsp;→ 8&nbsp;→ 81&nbsp;→ 162</p>



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



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



<div class="wp-block-uagb-container uagb-block-789cb5d6 alignfull uagb-is-root-container"><div class="uagb-container-inner-blocks-wrap">
<div class="wp-block-uagb-container uagb-block-dd969038">
<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="">100 40021</pre>
</div>



<div class="wp-block-uagb-container uagb-block-32bc121e">
<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</pre>
</div>
</div></div>



<p>100&nbsp;→ 200&nbsp;→ 2001&nbsp;→ 4002&nbsp;→ 40021</p>



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



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



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



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



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



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



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



<p>DFS(재귀)를 이용하여 해결</p>



<p>재귀를 수행하면서 조건을 만족할 수 없다면 Return</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 MinRes = INT16_MAX;
long long int Target = 0;

void Recursion(int _depth, long long int _val) {
    // 목표 값보다 크면 반환
    if (_val > Target)
        return;

    // 현재 깊이가 최소값보다 크면 반환
    if (_depth > MinRes)
        return;

    // 목표 값에 도달하면 최소 깊이 갱신
    if (Target == _val) {
        MinRes = min(MinRes, _depth);
        return;
    }

    // 재귀 호출을 통해 2를 곱하거나 1을 추가
    Recursion(_depth + 1, _val * 2);
    Recursion(_depth + 1, (_val * 10) + 1);
}

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

    long long int Start = 0;
    cin >> Start >> Target;
    
    // 초기 깊이는 1로 설정
    Recursion(1, Start);
    
    // 결과 출력: 만들 수 없는 경우 -1 출력
    if (INT16_MAX == MinRes)
        cout &lt;&lt; -1;
    else
        cout &lt;&lt; MinRes;
}
</pre>



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



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1039" height="113" src="https://lycos7560.com/wp-content/uploads/2024/10/image-11.png" alt="" class="wp-image-38377" srcset="https://lycos7560.com/wp-content/uploads/2024/10/image-11.png 1039w, https://lycos7560.com/wp-content/uploads/2024/10/image-11-300x33.png 300w, https://lycos7560.com/wp-content/uploads/2024/10/image-11-768x84.png 768w" sizes="(max-width: 1039px) 100vw, 1039px" /></figure>



<p>int =&gt; long long int</p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-16953%eb%b2%88-a-%e2%86%92-b-c-baekjoon/38376/">백준 16953번 (A → B, 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-16953%eb%b2%88-a-%e2%86%92-b-c-baekjoon/38376/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1240번 (노드사이의 거리, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-1240%eb%b2%88-%eb%85%b8%eb%93%9c%ec%82%ac%ec%9d%b4%ec%9d%98-%ea%b1%b0%eb%a6%ac-c-baekjoon/37874/</link>
					<comments>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-1240%eb%b2%88-%eb%85%b8%eb%93%9c%ec%82%ac%ec%9d%b4%ec%9d%98-%ea%b1%b0%eb%a6%ac-c-baekjoon/37874/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 04 Mar 2024 15:51:29 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1240]]></category>
		<category><![CDATA[1240 C++]]></category>
		<category><![CDATA[1240번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[dfs]]></category>
		<category><![CDATA[Gold]]></category>
		<category><![CDATA[Gold5]]></category>
		<category><![CDATA[Recursive]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[골드]]></category>
		<category><![CDATA[골드5]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[깊이]]></category>
		<category><![CDATA[깊이 우선 탐색]]></category>
		<category><![CDATA[노드사이의 거리]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1240]]></category>
		<category><![CDATA[백준 1240번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[재귀]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=37874</guid>

					<description><![CDATA[<p>백준 온라인 문제 1240번 문제에 대한 글입니다.<br />
DFS 재귀 함수를 사용하여 해결하였습니다.  (This is about question 1240 of Baekjun Online Problem.<br />
Resolved using the DFS recursive function.)</p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-1240%eb%b2%88-%eb%85%b8%eb%93%9c%ec%82%ac%ec%9d%b4%ec%9d%98-%ea%b1%b0%eb%a6%ac-c-baekjoon/37874/">백준 1240번 (노드사이의 거리, 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><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>



<h2 class="wp-block-heading">노드사이의 거리 <img decoding="async" width="30" height="38" class="wp-image-37889" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Gold_5.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Gold_5.jpg 1250w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-234x300.jpg 234w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-768x983.jpg 768w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-1200x1536.jpg 1200w" sizes="(max-width: 30px) 100vw, 30px" /></h2>



<p><a href="https://www.acmicpc.net/problem/1240" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1240</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">2 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">9018</td><td class="has-text-align-left" data-align="left">4874</td><td class="has-text-align-left" data-align="left">3752</td><td class="has-text-align-left" data-align="left">53.638%</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개의 노드로 이루어진 트리가 주어지고 M개의 두 노드 쌍을 입력받을 때 두 노드 사이의 거리를 출력하라.</p>



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



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



<p>첫째 줄에 노드의 개수&nbsp;N과 거리를 알고 싶은 노드 쌍의 개수&nbsp;M이 입력되고 다음&nbsp;N-1개의 줄에 트리 상에 연결된 두 점과 거리를 입력받는다. </p>



<p>그 다음 줄에는 거리를 알고 싶은&nbsp;M개의 노드 쌍이 한 줄에 한 쌍씩 입력된다.</p>



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



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



<p> M개의 줄에 차례대로 입력받은 두 노드 사이의 거리를 출력한다.</p>



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



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



<ul class="wp-block-list">
<li> 2 ≤ N ≤1,000 </li>



<li> 1 ≤ M ≤ 1,000 </li>



<li>트리 상에 연결된 두 점과 거리는&nbsp;10,000&nbsp;이하인 자연수이다.</li>



<li>트리 노드의 번호는&nbsp;1부터&nbsp;N까지 자연수이며, 두 노드가 같은 번호를 갖는 경우는 없다.</li>
</ul>



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



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<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="">4 2
2 1 2
4 3 2
1 4 3
1 2
3 2</pre>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<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="">2
7</pre>
</div>
</div>



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



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



<ul class="wp-block-list">
<li>빠진 조건을 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/hg7258" target="_blank" rel="noreferrer noopener">hg7258</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/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/120" target="_blank" rel="noreferrer noopener">트리</a></li>



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



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



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



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



<p>DFS를 이용하여 탐색</p>



<p>리펙토링하면 메모리와 시간을 더 줄일 수 있음</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;vector>

using namespace std;

constexpr int MAX = 1001;

int N, M, _End;

vector&lt;int> Nodes[MAX];
vector&lt;int> Distances[MAX][MAX];
bool IsVisted[MAX];


void DFS(int _Len, int _CurNode)
{
	if (_End == _CurNode) {
		cout &lt;&lt; _Len &lt;&lt; '\n';
		return;
	}

	for (int i = 0; i &lt; Nodes[_CurNode].size(); i++)
	{
		int NextNode = Nodes[_CurNode][i];
		if (IsVisted[NextNode]) 
			continue;
		IsVisted[NextNode] = true;
		DFS(_Len + *Distances[_CurNode][NextNode].begin(), NextNode);
		IsVisted[NextNode] = false;
	}

}

int main()
{
	cin >> N >> M;
	int _S, _E, _D;
	for (int i = 0; i &lt; N-1; i++) {
		cin >> _S >> _E >> _D;
		Nodes[_S].push_back(_E);
		Nodes[_E].push_back(_S);
		Distances[_S][_E].push_back(_D);
		Distances[_E][_S].push_back(_D);
	}

	for (int i = 0; i &lt; M; i++) {
		cin >> _S >> _E;
		_End = _E;
		IsVisted[_S] = true;
		DFS(0, _S);
		IsVisted[_S] = false;
	}


	return 0;
}</pre>



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



<p>방문 체크를 빼먹어서 틀렸다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="830" height="120" src="https://lycos7560.com/wp-content/uploads/2024/03/image.png" alt="" class="wp-image-37875" srcset="https://lycos7560.com/wp-content/uploads/2024/03/image.png 830w, https://lycos7560.com/wp-content/uploads/2024/03/image-300x43.png 300w, https://lycos7560.com/wp-content/uploads/2024/03/image-768x111.png 768w" sizes="(max-width: 830px) 100vw, 830px" /></figure>



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



<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="">    ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
    cin.tie(NULL);
    cout.tie(NULL);</pre>



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

using namespace std;

constexpr int MAX = 1001;

int N, M, _End;

vector&lt;int> Nodes[MAX];
vector&lt;int> Distances[MAX][MAX];
bool IsVisted[MAX];


void DFS(int _Len, int _CurNode)
{
	if (_End == _CurNode) {
		cout &lt;&lt; _Len &lt;&lt; '\n';
		return;
	}

	for (int i = 0; i &lt; Nodes[_CurNode].size(); i++)
	{
		int NextNode = Nodes[_CurNode][i];
		if (IsVisted[NextNode]) 
			continue;
		IsVisted[NextNode] = true;
		DFS(_Len + *Distances[_CurNode][NextNode].begin(), NextNode);
		IsVisted[NextNode] = false;
	}

}

int main()
{
    ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
    cin.tie(NULL);
    cout.tie(NULL);
	cin >> N >> M;
	int _S, _E, _D;
	for (int i = 0; i &lt; N-1; i++) {
		cin >> _S >> _E >> _D;
		Nodes[_S].push_back(_E);
		Nodes[_E].push_back(_S);
		Distances[_S][_E].push_back(_D);
		Distances[_E][_S].push_back(_D);
	}

	for (int i = 0; i &lt; M; i++) {
		cin >> _S >> _E;
		_End = _E;
		IsVisted[_S] = true;
		DFS(0, _S);
		IsVisted[_S] = false;
	}


	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="834" height="84" src="https://lycos7560.com/wp-content/uploads/2024/03/image-1.png" alt="" class="wp-image-37877" srcset="https://lycos7560.com/wp-content/uploads/2024/03/image-1.png 834w, https://lycos7560.com/wp-content/uploads/2024/03/image-1-300x30.png 300w, https://lycos7560.com/wp-content/uploads/2024/03/image-1-768x77.png 768w" sizes="(max-width: 834px) 100vw, 834px" /></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="4386247858"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<p></p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-1240%eb%b2%88-%eb%85%b8%eb%93%9c%ec%82%ac%ec%9d%b4%ec%9d%98-%ea%b1%b0%eb%a6%ac-c-baekjoon/37874/">백준 1240번 (노드사이의 거리, 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-1240%eb%b2%88-%eb%85%b8%eb%93%9c%ec%82%ac%ec%9d%b4%ec%9d%98-%ea%b1%b0%eb%a6%ac-c-baekjoon/37874/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 5639번 (이진 검색 트리, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-5639%eb%b2%88-%ec%9d%b4%ec%a7%84-%ea%b2%80%ec%83%89-%ed%8a%b8%eb%a6%ac-c-baekjoon/36556/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-5639%eb%b2%88-%ec%9d%b4%ec%a7%84-%ea%b2%80%ec%83%89-%ed%8a%b8%eb%a6%ac-c-baekjoon/36556/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 23 Aug 2023 04:20:19 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[5639]]></category>
		<category><![CDATA[5639번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[endoffile]]></category>
		<category><![CDATA[EOF]]></category>
		<category><![CDATA[Gold]]></category>
		<category><![CDATA[Gold5]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[골드]]></category>
		<category><![CDATA[골드5]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[그래프]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 5639]]></category>
		<category><![CDATA[백준 5639번]]></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=36556</guid>

					<description><![CDATA[<p>백준 온라인 저지 5639번 문제 '이진 검색 트리' 에 대한 글입니다. 단순한 재귀를 이용하여 해결하였습니다. (Baekjoon Online Judge Number 5639 This article is about the binary search tree. It was solved using simple recursion.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-5639%eb%b2%88-%ec%9d%b4%ec%a7%84-%ea%b2%80%ec%83%89-%ed%8a%b8%eb%a6%ac-c-baekjoon/36556/">백준 5639번 (이진 검색 트리, 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-37922" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-1.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-1.jpg 1250w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-1-234x300.jpg 234w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-1-768x983.jpg 768w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-1-1200x1536.jpg 1200w" sizes="(max-width: 30px) 100vw, 30px" /></h1>



<p><a href="https://www.acmicpc.net/problem/5639" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/5639</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">35442</td><td class="has-text-align-left" data-align="left">13888</td><td class="has-text-align-left" data-align="left">9821</td><td class="has-text-align-left" data-align="left">38.260%</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>이진 검색 트리는 다음과 같은 세 가지 조건을 만족하는 이진 트리이다.</p>



<ul class="wp-block-list">
<li>노드의 왼쪽 서브트리에 있는 모든 노드의 키는 노드의 키보다 작다.</li>



<li>노드의 오른쪽 서브트리에 있는 모든 노드의 키는 노드의 키보다 크다.</li>



<li>왼쪽, 오른쪽 서브트리도 이진 검색 트리이다.</li>
</ul>



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



<figure class="wp-block-image size-full"><img decoding="async" width="677" height="315" src="https://lycos7560.com/wp-content/uploads/2023/08/image-17.png" alt="" class="wp-image-36557" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-17.png 677w, https://lycos7560.com/wp-content/uploads/2023/08/image-17-300x140.png 300w" sizes="(max-width: 677px) 100vw, 677px" /></figure>



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



<p>전위 순회 (루트-왼쪽-오른쪽)은 루트를 방문하고, 왼쪽 서브트리, 오른쪽 서브 트리를 순서대로 방문하면서 노드의 키를 출력한다. </p>



<p>후위 순회 (왼쪽-오른쪽-루트)는 왼쪽 서브트리, 오른쪽 서브트리, 루트 노드 순서대로 키를 출력한다. </p>



<p>예를 들어, 위의 이진 검색 트리의 전위 순회 결과는 50 30 24 5 28 45 98 52 60 이고, 후위 순회 결과는 5 28 24 45 30 60 52 98 50 이다.</p>



<p>이진 검색 트리를 전위 순회한 결과가 주어졌을 때, 이 트리를 후위 순회한 결과를 구하는 프로그램을 작성하시오.</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>노드에 들어있는 키의 값은 10<sup>6</sup>보다 작은 양의 정수이다. </p>



<p>모든 값은 한 줄에 하나씩 주어지며, 노드의 수는 10,000개 이하이다. </p>



<p>같은 키를 가지는 노드는 없다.</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>



<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="">50
30
24
5
28
45
98
52
60</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="">5
28
24
45
30
60
52
98
50</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/1" target="_blank" rel="noreferrer noopener">ICPC</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/7" target="_blank" rel="noreferrer noopener">Regionals</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/42" target="_blank" rel="noreferrer noopener">Asia Pacific</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/102" target="_blank" rel="noreferrer noopener">Thailand</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/562" target="_blank" rel="noreferrer noopener">2011 ACM-ICPC Asia Phuket Regional Programming Contest</a>&nbsp;B번</p>



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



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



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

using namespace std;

struct BinaryNode
{
    int _Num;
    BinaryNode* _Left;
    BinaryNode* _Right;

    BinaryNode(int num)
        : _Num(num), _Left(nullptr), _Right(nullptr)
    {}

    void ArrayBinaryNode(int _n)
    {
        if (_Num > _n) {
            if (_Left == nullptr) _Left = new BinaryNode(_n);
            else _Left->ArrayBinaryNode(_n);
        }
        else {
            if (_Right == nullptr) _Right = new BinaryNode(_n);
            else _Right->ArrayBinaryNode(_n);
        }
    }
};

void PostorderTraverse(BinaryNode&amp; CurrentNode)
{
    if (CurrentNode._Left != nullptr) PostorderTraverse(*CurrentNode._Left);
    if (CurrentNode._Right != nullptr) PostorderTraverse(*CurrentNode._Right);
    cout &lt;&lt; CurrentNode._Num &lt;&lt; "\n";
}


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

    int _N;
    cin >> _N;
    BinaryNode _RootNode(_N);
    while (true) {
        cin >> _N;
        if (cin.eof() == true)
            break;
        _RootNode.ArrayBinaryNode(_N);
    }

    PostorderTraverse(_RootNode);

	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="1076" height="98" src="https://lycos7560.com/wp-content/uploads/2023/08/image-18.png" alt="" class="wp-image-36561" style="width:927px;height:84px" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-18.png 1076w, https://lycos7560.com/wp-content/uploads/2023/08/image-18-300x27.png 300w, https://lycos7560.com/wp-content/uploads/2023/08/image-18-768x70.png 768w" sizes="(max-width: 1076px) 100vw, 1076px" /></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/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-5639%eb%b2%88-%ec%9d%b4%ec%a7%84-%ea%b2%80%ec%83%89-%ed%8a%b8%eb%a6%ac-c-baekjoon/36556/">백준 5639번 (이진 검색 트리, 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-5639%eb%b2%88-%ec%9d%b4%ec%a7%84-%ea%b2%80%ec%83%89-%ed%8a%b8%eb%a6%ac-c-baekjoon/36556/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 21736번 (헌내기는 친구가 필요해, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-21736%eb%b2%88-%ed%97%8c%eb%82%b4%ea%b8%b0%eb%8a%94-%ec%b9%9c%ea%b5%ac%ea%b0%80-%ed%95%84%ec%9a%94%ed%95%b4-c-baekjoon/36032/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-21736%eb%b2%88-%ed%97%8c%eb%82%b4%ea%b8%b0%eb%8a%94-%ec%b9%9c%ea%b5%ac%ea%b0%80-%ed%95%84%ec%9a%94%ed%95%b4-c-baekjoon/36032/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 12 Jul 2023 22:14:25 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[dfs]]></category>
		<category><![CDATA[Recursive]]></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[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36032</guid>

					<description><![CDATA[<p>백준 21736번 '헌내기는 친구가 필요해' 문제에 대한 글입니다. 재귀를 이용한 'DFS Search'을 이용하여 해결하였습니다. (Baekjoon Number 21736 This is an article about the problem of "The old man needs a friend." It was solved by using 'DFS Search' using recursive.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-21736%eb%b2%88-%ed%97%8c%eb%82%b4%ea%b8%b0%eb%8a%94-%ec%b9%9c%ea%b5%ac%ea%b0%80-%ed%95%84%ec%9a%94%ed%95%b4-c-baekjoon/36032/">백준 21736번 (헌내기는 친구가 필요해, 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-e89d25e2      "
					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:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">헌내기는 친구가 필요해</h1>



<p><a href="https://www.acmicpc.net/problem/21736" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/21736</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 초 (<a href="https://www.acmicpc.net/problem/21736#" target="_blank" rel="noreferrer noopener">하단 참고</a>)</td><td class="has-text-align-left" data-align="left">1024 MB</td><td class="has-text-align-left" data-align="left">3403</td><td class="has-text-align-left" data-align="left">1990</td><td class="has-text-align-left" data-align="left">1668</td><td class="has-text-align-left" data-align="left">60.943%</td></tr></tbody></table></figure>



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



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



<p>2020년에 입학한 헌내기 도연이가 있다. 도연이는 비대면 수업 때문에 학교에&nbsp;가지 못해 학교에 아는 친구가 없었다. </p>



<p>드디어 대면 수업을 하게 된 도연이는 어서 캠퍼스 내의 사람들과 친해지고 싶다.&nbsp;</p>



<p>도연이가 다니는 대학의 캠퍼스는&nbsp;N x M&nbsp;크기이며&nbsp;캠퍼스에서 이동하는&nbsp;방법은 벽이 아닌 상하좌우로 이동하는 것이다. </p>



<p>예를 들어, 도연이가 (x,&nbsp;y)에 있다면 이동할 수 있는 곳은 (x+1,&nbsp;y), (x,&nbsp;y+1), (x-1,&nbsp;y), (x,&nbsp;y-1)이다. </p>



<p>단, 캠퍼스의 밖으로 이동할 수는 없다.</p>



<p>불쌍한 도연이를 위하여 캠퍼스에서 도연이가 만날 수 있는 사람의 수를 출력하는 프로그램을 작성해보자.</p>



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



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



<p>첫째 줄에는 캠퍼스의 크기를 나타내는 두 정수&nbsp;N&nbsp;(1 ≤ N ≤ 600),&nbsp;M&nbsp;(1 ≤ M ≤ 600)이 주어진다.</p>



<p>둘째 줄부터&nbsp;N개의 줄에는 캠퍼스의 정보들이 주어진다.&nbsp;</p>



<p><code>O</code>는 빈 공간,&nbsp;<code>X</code>는 벽,&nbsp;<code>I</code>는 도연이,&nbsp;<code>P</code>는 사람이다.&nbsp;</p>



<p><code>I</code>가 한 번만 주어짐이 보장된다.</p>



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



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



<p>첫째 줄에 도연이가 만날 수 있는 사람의 수를 출력한다. </p>



<p>단, 아무도 만나지 못한 경우&nbsp;<code>TT</code>를 출력한다.</p>



<div style="height:62px" 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
OOOPO
OIOOX
OOOXP</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="">1</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 2</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 3
IOX
OXP
XPP</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 2</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="">TT</pre>



<div style="height:40px" 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/5" target="_blank" rel="noreferrer noopener">University</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/527" target="_blank" rel="noreferrer noopener">숙명여자대학교</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/2539" target="_blank" rel="noreferrer noopener">제1회 숙명여자대학교 교내 알고리즘 경진대회 (SMUPC)</a>&nbsp;C번</p>



<ul class="wp-block-list">
<li>문제를 검수한 사람:&nbsp;<a href="https://www.acmicpc.net/user/cs71107" target="_blank" rel="noreferrer noopener">cs71107</a>,&nbsp;<a href="https://www.acmicpc.net/user/lky7674" target="_blank" rel="noreferrer noopener">lky7674</a>,&nbsp;<a href="https://www.acmicpc.net/user/plast" target="_blank" rel="noreferrer noopener">plast</a>,&nbsp;<a href="https://www.acmicpc.net/user/sait2000" target="_blank" rel="noreferrer noopener">sait2000</a>,&nbsp;<a href="https://www.acmicpc.net/user/songfox00" target="_blank" rel="noreferrer noopener">songfox00</a>,&nbsp;<a href="https://www.acmicpc.net/user/wbcho0504" target="_blank" rel="noreferrer noopener">wbcho0504</a>,&nbsp;<a href="https://www.acmicpc.net/user/whaeun25" target="_blank" rel="noreferrer noopener">whaeun25</a></li>



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



<div style="height:62px" 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/7" target="_blank" rel="noreferrer noopener">그래프 이론</a></li>



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



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



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



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



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



<p>DFS 탐색을 재귀로 구현하여 문제를 해결</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>
using namespace std;
int _Res = 0, _N, _M;
int _DxDy[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };
char _Map[600][600];
string _Str;
char _Temp;
pair&lt;int, int> StartPos;

// 재귀를 이용한 DFS (Depth-First Search) 탐색 
void DFSSearch(int _CntX, int _CntY)
{
	for (int j = 0; j &lt; 4; j++) {
		int _dx = _CntX + _DxDy[j][0];
		int _dy = _CntY + _DxDy[j][1];
		if (_dx >= _N || _dy >= _M || _dx &lt; 0 || _dy &lt; 0)
			continue;
		if (_Map[_dx][_dy] == 'X')
			continue;
		if (_Map[_dx][_dy] == 'P')
			_Res++;
		// 방문처리 대신에 X(벽)으로 마킹
		_Map[_dx][_dy] = 'X';
		DFSSearch(_dx, _dy);
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> _N >> _M;
	for (int i = 0; i &lt; _N; i++) {
		cin >> _Str;
		for (int j = 0; j &lt; _M; j++) {
			_Map[i][j] = _Str[j];
			if (_Str[j] == 'I') {
				StartPos = make_pair(i, j);
				_Map[i][j] = 'X';
			}
		}
	}
	
	DFSSearch(StartPos.first, StartPos.second);

	if (_Res == 0) cout &lt;&lt; "TT"; 
	else  cout &lt;&lt; _Res;

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1064" height="45" src="https://lycos7560.com/wp-content/uploads/2023/07/image-31.png" alt="" class="wp-image-36040" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-31.png 1064w, https://lycos7560.com/wp-content/uploads/2023/07/image-31-300x13.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-31-768x32.png 768w" sizes="(max-width: 1064px) 100vw, 1064px" /></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-21736%eb%b2%88-%ed%97%8c%eb%82%b4%ea%b8%b0%eb%8a%94-%ec%b9%9c%ea%b5%ac%ea%b0%80-%ed%95%84%ec%9a%94%ed%95%b4-c-baekjoon/36032/">백준 21736번 (헌내기는 친구가 필요해, 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-21736%eb%b2%88-%ed%97%8c%eb%82%b4%ea%b8%b0%eb%8a%94-%ec%b9%9c%ea%b5%ac%ea%b0%80-%ed%95%84%ec%9a%94%ed%95%b4-c-baekjoon/36032/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Programmers 92342 양궁대회 [2022 KAKAO BLIND RECRUITMENT]</title>
		<link>https://lycos7560.com/cpp/programmers/programmers-92342-%ec%96%91%ea%b6%81%eb%8c%80%ed%9a%8c-2022-kakao-blind-recruitment/35277/</link>
					<comments>https://lycos7560.com/cpp/programmers/programmers-92342-%ec%96%91%ea%b6%81%eb%8c%80%ed%9a%8c-2022-kakao-blind-recruitment/35277/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 02 Jun 2023 12:22:01 +0000</pubDate>
				<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[[2022 KAKAO BLIND RECRUITMENT]]]></category>
		<category><![CDATA[2022 KAKAO BLIND RECRUITMENT]]></category>
		<category><![CDATA[92342]]></category>
		<category><![CDATA[92342번]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Programmers 92342]]></category>
		<category><![CDATA[Programmers 92342번]]></category>
		<category><![CDATA[Recursive]]></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>
		<guid isPermaLink="false">https://lycos7560.com/?p=35277</guid>

					<description><![CDATA[<p>Programmers 92342번 '양궁대회' 문제에 대한 글입니다. 재귀를 이용한 완전 탐색으로 해결하였습니다. (This article is about the issue of 'Archery Competition' in Programmers 92342. It was solved by a complete search using recursive. [2022 KAKAO BLIND RECRUITMENT]) [2022 KAKAO BLIND RECRUITMENT]</p>
<p>The post <a href="https://lycos7560.com/cpp/programmers/programmers-92342-%ec%96%91%ea%b6%81%eb%8c%80%ed%9a%8c-2022-kakao-blind-recruitment/35277/">Programmers 92342 양궁대회 [2022 KAKAO BLIND RECRUITMENT]</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: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-abaa38ce      "
					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://school.programmers.co.kr/learn/courses/30/lessons/92342" target="_blank" rel="noreferrer noopener">https://school.programmers.co.kr/learn/courses/30/lessons/92342</a></p>



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



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



<p class="has-medium-font-size">카카오배 양궁대회가 열렸습니다.</p>



<p class="has-medium-font-size"><code>라이언</code>은 저번 카카오배 양궁대회 우승자이고 이번 대회에도 결승전까지 올라왔습니다. </p>



<p class="has-medium-font-size">결승전 상대는&nbsp;<code>어피치</code>입니다.</p>



<p class="has-medium-font-size">카카오배 양궁대회 운영위원회는 한 선수의 연속 우승보다는 다양한 선수들이 양궁대회에서 우승하기를 원합니다. </p>



<p class="has-medium-font-size">따라서, 양궁대회 운영위원회는 결승전 규칙을 전 대회 우승자인 라이언에게 불리하게 다음과 같이 정했습니다.</p>



<ol class="wp-block-list">
<li>어피치가 화살&nbsp;<code>n</code>발을 다 쏜 후에 라이언이 화살&nbsp;<code>n</code>발을 쏩니다.</li>



<li>점수를 계산합니다.


<ol class="wp-block-list">
<li>과녁판은 아래 사진처럼 생겼으며 가장 작은 원의 과녁 점수는 10점이고 가장 큰 원의 바깥쪽은 과녁 점수가 0점입니다.&nbsp;</li>



<li>만약, k(k는 1~10사이의 자연수)점을 어피치가 a발을 맞혔고 라이언이 b발을 맞혔을 경우 더 많은 화살을 k점에 맞힌 선수가 k 점을 가져갑니다. <br>단, a = b일 경우는 어피치가 k점을 가져갑니다.&nbsp;<strong>k점을 여러 발 맞혀도 k점 보다 많은 점수를 가져가는 게 아니고 k점만 가져가는 것을 유의하세요. </strong><br><strong>또한 a = b = 0 인 경우, 즉, 라이언과 어피치 모두 k점에 단 하나의 화살도 맞히지 못한 경우는 어느 누구도 k점을 가져가지 않습니다.</strong></li>
</ol>



<ul class="wp-block-list">
<li>예를 들어, 어피치가 10점을 2발 맞혔고 라이언도 10점을 2발 맞혔을 경우 어피치가 10점을 가져갑니다.</li>



<li>다른 예로, 어피치가 10점을 0발 맞혔고 라이언이 10점을 2발 맞혔을 경우 라이언이 10점을 가져갑니다.</li>



<li>모든 과녁 점수에 대하여 각 선수의 최종 점수를 계산합니다.</li>
</ul>
</li>



<li>최종 점수가 더 높은 선수를 우승자로 결정합니다. <br>단, 최종 점수가 같을 경우&nbsp;어피치를 우승자로 결정합니다.</li>
</ol>



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



<figure class="wp-block-image size-full"><img decoding="async" width="723" height="678" src="https://lycos7560.com/wp-content/uploads/2023/06/image-1.png" alt="" class="wp-image-35279" srcset="https://lycos7560.com/wp-content/uploads/2023/06/image-1.png 723w, https://lycos7560.com/wp-content/uploads/2023/06/image-1-300x281.png 300w" sizes="(max-width: 723px) 100vw, 723px" /></figure>



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



<p class="has-medium-font-size">현재 상황은 어피치가 화살&nbsp;<code>n</code>발을 다 쏜 후이고 라이언이 화살을 쏠 차례입니다.</p>



<p class="has-medium-font-size">라이언은 어피치를 가장 큰 점수 차이로 이기기 위해서&nbsp;<code>n</code>발의 화살을 어떤 과녁 점수에 맞혀야 하는지를 구하려고 합니다.</p>



<p class="has-medium-font-size">화살의 개수를 담은 자연수&nbsp;<code>n</code>, 어피치가 맞힌 과녁 점수의 개수를 10점부터 0점까지 순서대로 담은 정수 배열&nbsp;<code>info</code>가 매개변수로 주어집니다. </p>



<p class="has-medium-font-size">이때, 라이언이 가장 큰 점수 차이로 우승하기 위해&nbsp;<code>n</code>발의 화살을 어떤 과녁 점수에 맞혀야 하는지를 </p>



<p class="has-medium-font-size">10점부터 0점까지 순서대로 정수 배열에 담아 return 하도록 solution 함수를 완성해 주세요. </p>



<p class="has-medium-font-size">만약, 라이언이 우승할 수 없는 경우(무조건 지거나 비기는 경우)는&nbsp;<code>[-1]</code>을 return 해주세요.</p>



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



<h5 class="wp-block-heading has-large-font-size">제한사항</h5>



<ul class="wp-block-list">
<li>1 ≤&nbsp;<code>n</code>&nbsp;≤ 10</li>



<li><code>info</code>의 길이 = 11
<ul class="wp-block-list">
<li>0 ≤&nbsp;<code>info</code>의 원소 ≤&nbsp;<code>n</code></li>



<li><code>info</code>의 원소 총합 =&nbsp;<code>n</code></li>



<li><code>info</code>의 i번째 원소는 과녁의&nbsp;<code>10 - i</code>&nbsp;점을 맞힌 화살 개수입니다. ( i는 0~10 사이의 정수입니다.)</li>
</ul>
</li>



<li>라이언이 우승할 방법이 있는 경우, return 할 정수 배열의 길이는 11입니다.
<ul class="wp-block-list">
<li>0 ≤ return할 정수 배열의 원소 ≤&nbsp;<code>n</code></li>



<li>return할 정수 배열의 원소 총합 =&nbsp;<code>n</code>&nbsp;(꼭 n발을 다 쏴야 합니다.)</li>



<li>return할 정수 배열의 i번째 원소는 과녁의&nbsp;<code>10 - i</code>&nbsp;점을 맞힌 화살 개수입니다. ( i는 0~10 사이의 정수입니다.)</li>



<li><strong>라이언이 가장 큰 점수 차이로 우승할 수 있는 방법이 여러 가지 일 경우, 가장 낮은 점수를 더 많이 맞힌 경우를 return 해주세요.</strong>
<ul class="wp-block-list">
<li>가장 낮은 점수를 맞힌 개수가 같을 경우 계속해서 그다음으로 낮은 점수를 더 많이 맞힌 경우를 return 해주세요.</li>



<li>예를 들어,&nbsp;<code>[2,3,1,0,0,0,0,1,3,0,0]</code>과&nbsp;<code>[2,1,0,2,0,0,0,2,3,0,0]</code>를 비교하면&nbsp;<code>[2,1,0,2,0,0,0,2,3,0,0]</code>를 return 해야 합니다.</li>



<li>다른 예로,&nbsp;<code>[0,0,2,3,4,1,0,0,0,0,0]</code>과&nbsp;<code>[9,0,0,0,0,0,0,0,1,0,0]</code>를 비교하면<code>[9,0,0,0,0,0,0,0,1,0,0]</code>를 return 해야 합니다.</li>
</ul>
</li>
</ul>
</li>



<li>라이언이 우승할 방법이 없는 경우, return 할 정수 배열의 길이는 1입니다.
<ul class="wp-block-list">
<li>라이언이 어떻게 화살을 쏘든&nbsp;<strong>라이언의 점수가 어피치의 점수보다 낮거나 같으면&nbsp;<code>[-1]</code>을 return 해야 합니다.</strong></li>
</ul>
</li>
</ul>



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



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



<figure class="wp-block-table"><table><thead><tr><th class="has-text-align-left" data-align="left">n</th><th class="has-text-align-left" data-align="left">info</th><th class="has-text-align-left" data-align="left">result</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left">[2,1,1,1,0,0,0,0,0,0,0]</td><td class="has-text-align-left" data-align="left">[0,2,2,0,1,0,0,0,0,0,0]</td></tr><tr><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">[1,0,0,0,0,0,0,0,0,0,0]</td><td class="has-text-align-left" data-align="left">[-1]</td></tr><tr><td class="has-text-align-left" data-align="left">9</td><td class="has-text-align-left" data-align="left">[0,0,1,2,0,1,1,1,1,1,1]</td><td class="has-text-align-left" data-align="left">[1,1,2,0,1,2,2,0,0,0,0]</td></tr><tr><td class="has-text-align-left" data-align="left">10</td><td class="has-text-align-left" data-align="left">[0,0,0,0,0,0,0,0,3,4,3]</td><td class="has-text-align-left" data-align="left">[1,1,1,1,1,1,1,1,0,0,2]</td></tr></tbody></table></figure>



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



<h5 class="wp-block-heading has-large-font-size">입출력 예 설명</h5>



<p class="has-medium-font-size"><strong>입출력 예 #1</strong></p>



<p class="has-medium-font-size">어피치와 라이언이 아래와 같이 화살을 맞힐 경우,</p>



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



<figure 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></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">10</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">3</td><td class="has-text-align-left" data-align="left">라이언이 10점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">9</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">라이언이 9점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">8</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">어피치가 8점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">7</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">어피치가 7점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">6</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left"></td></tr><tr><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left"></td></tr><tr><td class="has-text-align-left" data-align="left">4</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left"></td></tr><tr><td class="has-text-align-left" data-align="left">3</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left"></td></tr><tr><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left"></td></tr><tr><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left"></td></tr><tr><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left"></td></tr></tbody></table></figure>



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



<p class="has-medium-font-size">어피치의 최종 점수는 15점, 라이언의 최종 점수는 19점입니다. 4점 차이로 라이언이 우승합니다.</p>



<p class="has-medium-font-size">하지만, 라이언이 아래와 같이 화살을 맞힐 경우 더 큰 점수 차로 우승할 수 있습니다.</p>



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



<figure class="wp-block-table"><table><thead><tr><th>과녁 점수</th><th>어피치가 맞힌 화살 개수</th><th>라이언이 맞힌 화살 개수</th><th>결과</th></tr></thead><tbody><tr><td>10</td><td>2</td><td>0</td><td>어피치가 10점 획득</td></tr><tr><td>9</td><td>1</td><td>2</td><td>라이언이 9점 획득</td></tr><tr><td>8</td><td>1</td><td>2</td><td>라이언이 8점 획득</td></tr><tr><td>7</td><td>1</td><td>0</td><td>어피치가 7점 획득</td></tr><tr><td>6</td><td>0</td><td>1</td><td>라이언이 6점 획득</td></tr><tr><td>5</td><td>0</td><td>0</td><td></td></tr><tr><td>4</td><td>0</td><td>0</td><td></td></tr><tr><td>3</td><td>0</td><td>0</td><td></td></tr><tr><td>2</td><td>0</td><td>0</td><td></td></tr><tr><td>1</td><td>0</td><td>0</td><td></td></tr><tr><td>0</td><td>0</td><td>0</td><td></td></tr></tbody></table></figure>



<p class="has-medium-font-size">어피치의 최종 점수는 17점, 라이언의 최종 점수는 23점입니다. 6점 차이로 라이언이 우승합니다.</p>



<p class="has-medium-font-size">따라서&nbsp;<code>[0,2,2,0,1,0,0,0,0,0,0]</code>을 return 해야 합니다.</p>



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



<p class="has-medium-font-size"><strong>입출력 예 #2</strong></p>



<p class="has-medium-font-size">라이언이 10점을 맞혀도 어피치가 10점을 가져가게 됩니다.</p>



<p class="has-medium-font-size">따라서, 라이언은 우승할 수 없기 때문에&nbsp;<code>[-1]</code>을 return 해야 합니다.</p>



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



<p class="has-medium-font-size"><strong>입출력 예 #3</strong></p>



<p class="has-medium-font-size">어피치와 라이언이 아래와 같이 화살을 맞힐 경우,</p>



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



<figure 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></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">10</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">라이언이 10점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">9</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">라이언이 9점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">8</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">라이언이 8점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">7</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">3</td><td class="has-text-align-left" data-align="left">라이언이 7점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">6</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left"></td></tr><tr><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">라이언이 5점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">4</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">어피치가 4점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">3</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">어피치가 3점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">어피치가 2점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">어피치가 1점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">어피치가 0점 획득</td></tr></tbody></table></figure>



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



<p class="has-medium-font-size">어피치의 최종 점수는 10점, 라이언의 최종 점수는 39점입니다. </p>



<p class="has-medium-font-size">29점 차이로 라이언이 우승합니다.</p>



<p class="has-medium-font-size">하지만 라이언이 아래와 같이 화살을 맞힐 경우,</p>



<figure 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></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">10</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">라이언이 10점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">9</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">라이언이 9점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">8</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">라이언이 8점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">7</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">어피치가 7점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">6</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">라이언이 6점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">라이언이 5점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">4</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">라이언이 4점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">3</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">어피치가 3점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">어피치가 2점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">어피치가 1점 획득</td></tr><tr><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">어피치가 0점 획득</td></tr></tbody></table></figure>



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



<p>어피치의 최종 점수는 13점, 라이언의 최종 점수는 42점입니다. </p>



<p>이 경우도 29점 차이로 라이언이 우승합니다.</p>



<p>하지만, 첫 번째 경우와 두 번째 경우를 비교했을 때, </p>



<p>두 번째 경우가 두 경우 중 가장 낮은 점수인 4점을 더 많이 맞혔기 때문에&nbsp;</p>



<p><code>[1,1,2,3,0,2,0,0,0,0,0]</code>이 아닌&nbsp;<code>[1,1,2,0,1,2,2,0,0,0,0]</code>을 return 해야 합니다.</p>



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



<p class="has-medium-font-size"><strong>입출력 예 #4</strong></p>



<p class="has-medium-font-size">가장 큰 점수 차이로 이기는 경우 중에서 가장 낮은 점수를 가장 많이 맞힌, </p>



<p class="has-medium-font-size">10~3점을 한 발씩 맞히고 나머지 두 발을 0점에 맞히는 경우인&nbsp;<code>[1,1,1,1,1,1,1,1,0,0,2]</code>를 return 해야 합니다.</p>



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



<h5 class="wp-block-heading">제한시간 안내</h5>



<ul class="wp-block-list">
<li>정확성 테스트 : 10초</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>



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

using namespace std;

int _N, _LionRes, _ApeachRes, _Maxdiff;

vector&lt;int> _Answer = { -1 };

bool Check(vector&lt;int>&amp; _Answer, vector&lt;int>&amp; _ComparisonV)
{
    for (int i = 10; i >= 0; i--) {
        if (_Answer[i] &lt; _ComparisonV[i]) return true;
        else if (_Answer[i] > _ComparisonV[i]) return false;
    }
    return false;
}

// 완전 탐색
void Search(vector&lt;int>&amp; _apeachV, vector&lt;int>&amp; _ryanV, int _cnt, int _pivot)
{
    if (_cnt == _N) {
        _ApeachRes = 0; _LionRes = 0;
        for (int i = 0; i &lt; 10; i++) {
            if (_apeachV[i] &lt; _ryanV[i]) _LionRes += (10 - i);
            else if (_apeachV[i] > 0) _ApeachRes += (10 - i);
        }

        int _DiffValue = _LionRes - _ApeachRes;
        if ((_DiffValue > 0 &amp;&amp; _Maxdiff &lt;= _DiffValue)) {
            if (_Maxdiff == _DiffValue &amp;&amp; !Check(_Answer, _ryanV)) return;
            _Maxdiff = _DiffValue;
            _Answer = _ryanV;
        }
        return;
    }

    // 피봇을 이용하여 중복을 제거
    for (int i = _pivot; i &lt;= 10; i++) {
        _ryanV[i]++;
        Search(_apeachV, _ryanV, _cnt + 1, i);
        _ryanV[i]--;
    }

}

vector&lt;int> solution(int n, vector&lt;int> info) {
    _N = n;
    vector&lt;int> _BaseV = { 0,0,0,0,0,0,0,0,0,0,0 };
    Search(info, _BaseV, 0, 0);
    return _Answer;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="393" height="705" src="https://lycos7560.com/wp-content/uploads/2023/06/image-3.png" alt="" class="wp-image-35287" srcset="https://lycos7560.com/wp-content/uploads/2023/06/image-3.png 393w, https://lycos7560.com/wp-content/uploads/2023/06/image-3-167x300.png 167w" sizes="(max-width: 393px) 100vw, 393px" /></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/programmers/programmers-92342-%ec%96%91%ea%b6%81%eb%8c%80%ed%9a%8c-2022-kakao-blind-recruitment/35277/">Programmers 92342 양궁대회 [2022 KAKAO BLIND RECRUITMENT]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/programmers/programmers-92342-%ec%96%91%ea%b6%81%eb%8c%80%ed%9a%8c-2022-kakao-blind-recruitment/35277/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1991번 (트리 순회, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1991%eb%b2%88-%ed%8a%b8%eb%a6%ac-%ec%88%9c%ed%9a%8c-c-baekjoon/34768/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1991%eb%b2%88-%ed%8a%b8%eb%a6%ac-%ec%88%9c%ed%9a%8c-c-baekjoon/34768/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sat, 13 May 2023 14:48:11 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1991]]></category>
		<category><![CDATA[1991번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[InorderTraverse]]></category>
		<category><![CDATA[PostorderTraverse]]></category>
		<category><![CDATA[PreorderTraverse]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1991]]></category>
		<category><![CDATA[백준 1991번]]></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=34768</guid>

					<description><![CDATA[<p>백준 1991번 '트리 순회' 문제에 대한 글입니다. 재귀를 이용하여 해결하였습니다.recursive function<br />
(This article is about the issue of 'Tree Tour' in Baekjoon Number 1991. I solved it by using recursive function.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1991%eb%b2%88-%ed%8a%b8%eb%a6%ac-%ec%88%9c%ed%9a%8c-c-baekjoon/34768/">백준 1991번 (트리 순회, 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-4d1fa490      "
					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: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/1991" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1991</a></p>



<div style="height:62px" 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">2 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">45305</td><td class="has-text-align-left" data-align="left">29670</td><td class="has-text-align-left" data-align="left">22705</td><td class="has-text-align-left" data-align="left">66.529%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">이진 트리를 입력받아 전위 순회(preorder traversal), 중위 순회(inorder traversal), </p>



<p class="has-medium-font-size">후위 순회(postorder traversal)한 결과를 출력하는 프로그램을 작성하시오.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="483" height="332" src="https://lycos7560.com/wp-content/uploads/2023/05/image-78.png" alt="" class="wp-image-34769" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-78.png 483w, https://lycos7560.com/wp-content/uploads/2023/05/image-78-300x206.png 300w" sizes="(max-width: 483px) 100vw, 483px" /></figure>



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



<p class="has-medium-font-size">예를 들어 위와 같은 이진 트리가 입력되면,</p>



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



<p>전위 순회한 결과 : ABDCEFG // (루트) (왼쪽 자식) (오른쪽 자식)</p>



<p>중위 순회한 결과 : DBAECFG // (왼쪽 자식) (루트) (오른쪽 자식)</p>



<p>후위 순회한 결과 : DBEGFCA // (왼쪽 자식) (오른쪽 자식) (루트)</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">첫째 줄에는 이진 트리의 노드의 개수 N(1 ≤ N ≤ 26)이 주어진다. </p>



<p class="has-medium-font-size">둘째 줄부터 N개의 줄에 걸쳐 각 노드와 그의 왼쪽 자식 노드, 오른쪽 자식 노드가 주어진다. </p>



<p class="has-medium-font-size">노드의 이름은 A부터 차례대로 알파벳 대문자로 매겨지며, 항상 A가 루트 노드가 된다. </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">각 줄에 N개의 알파벳을 공백 없이 출력하면 된다.</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="">7
A B C
B D .
C E F
E . .
F . G
D . .
G . .</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="">ABDCEFG
DBAECFG
DBEGFCA</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/problem/tag/120" target="_blank" rel="noreferrer noopener">트리</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/62" 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: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;vector>
using namespace std;

struct Node;
vector&lt;Node> NodesV;
void PreorderTraverse(int _Cnt);
void PostorderTraverse(int _Cnt);
void InorderTraverse(int _Cnt);
int _N;
char _C, _L, _R;

struct Node
{
	int _Node;

	Node* _LeftNode;
	Node* _RightNode;

	Node(char _node)
	{
		_LeftNode = NULL;
		_RightNode = NULL;
		_Node = (int)_node - 65;
	}

	void ChangeNodeLeft(char NodeC)
	{
		if (NodeC == '.') return;
		_LeftNode = &amp;NodesV[(int)NodeC - 65];
	}

	void ChangeNodeRight(char NodeC)
	{
		if (NodeC == '.') return;
		_RightNode = &amp;NodesV[(int)NodeC - 65];
	}
};

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

	cin >> _N;
	for (int i = 0; i &lt; _N; i++) {
		Node TNode = Node((char)(65 + i));
		NodesV.push_back((char)(65 + i));
	}

	for (int i = 0; i &lt; _N; i++) {
		cin >> _C >> _L >> _R;
		NodesV[(int)_C - 65].ChangeNodeLeft(_L);
		NodesV[(int)_C - 65].ChangeNodeRight(_R);
	}

	PreorderTraverse(0);
	cout &lt;&lt; "\n";
	PostorderTraverse(0);
	cout &lt;&lt; "\n";
	InorderTraverse(0);
	return 0;
}

void PreorderTraverse(int _Cnt)
{
	cout &lt;&lt; (char)(_Cnt + 65);
	if (NodesV[_Cnt]._LeftNode != NULL)
		PreorderTraverse(NodesV[_Cnt]._LeftNode->_Node);
	if (NodesV[_Cnt]._RightNode != NULL)
		PreorderTraverse(NodesV[_Cnt]._RightNode->_Node);
}

void PostorderTraverse(int _Cnt)
{
	if (NodesV[_Cnt]._LeftNode != NULL)
		PostorderTraverse(NodesV[_Cnt]._LeftNode->_Node);
	cout &lt;&lt; (char)(_Cnt + 65);
	if (NodesV[_Cnt]._RightNode != NULL)
		PostorderTraverse(NodesV[_Cnt]._RightNode->_Node);
}

void InorderTraverse(int _Cnt)
{
	if (NodesV[_Cnt]._LeftNode != NULL)
		InorderTraverse(NodesV[_Cnt]._LeftNode->_Node);
	if (NodesV[_Cnt]._RightNode != NULL)
		InorderTraverse(NodesV[_Cnt]._RightNode->_Node);
	cout &lt;&lt; (char)(_Cnt + 65);
}
</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1205" height="101" src="https://lycos7560.com/wp-content/uploads/2023/05/image-79.png" alt="" class="wp-image-34772" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-79.png 1205w, https://lycos7560.com/wp-content/uploads/2023/05/image-79-300x25.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-79-768x64.png 768w" sizes="(max-width: 1205px) 100vw, 1205px" /></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></p>



<p></p>



<p></p>



<p></p>



<p></p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1991%eb%b2%88-%ed%8a%b8%eb%a6%ac-%ec%88%9c%ed%9a%8c-c-baekjoon/34768/">백준 1991번 (트리 순회, 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-1991%eb%b2%88-%ed%8a%b8%eb%a6%ac-%ec%88%9c%ed%9a%8c-c-baekjoon/34768/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1992번 (쿼드트리, C++, DivideAndConquer) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1992%eb%b2%88-%ec%bf%bc%eb%93%9c%ed%8a%b8%eb%a6%ac-c-divideandconquer-baekjoon/33181/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1992%eb%b2%88-%ec%bf%bc%eb%93%9c%ed%8a%b8%eb%a6%ac-c-divideandconquer-baekjoon/33181/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 15 Feb 2023 20:32:23 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1992]]></category>
		<category><![CDATA[1992번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cin.tie(NULL)]]></category>
		<category><![CDATA[cout.tie(NULL)]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DivideAndConquer]]></category>
		<category><![CDATA[divisionconquest]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></category>
		<category><![CDATA[Recursive]]></category>
		<category><![CDATA[std]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1992]]></category>
		<category><![CDATA[백준 1992번]]></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=33181</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1992번 '쿼드트리' 문제에 대한 글입니다. '분할 정복' 알고리즘을 이용하여 해결하였습니다. (This is an article about the problem of 'Quad Tree' in 1992 by BAEKJOON. We solved it using 'DivideAndConquer' algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1992%eb%b2%88-%ec%bf%bc%eb%93%9c%ed%8a%b8%eb%a6%ac-c-divideandconquer-baekjoon/33181/">백준 1992번 (쿼드트리, C++, DivideAndConquer) / 추가 반례 [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-79efbce7      "
					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/1992" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1992</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">37409</td><td class="has-text-align-left" data-align="left">22836</td><td class="has-text-align-left" data-align="left">17917</td><td class="has-text-align-left" data-align="left">61.630%</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">흑백 영상을 압축하여 표현하는 데이터 구조로 쿼드 트리(Quad Tree)라는 방법이 있다. </p>



<p class="has-medium-font-size">흰 점을 나타내는 0과 검은 점을 나타내는 1로만 이루어진 영상(2차원 배열)에서 같은 숫자의 점들이 한 곳에 많이 몰려있으면, </p>



<p class="has-medium-font-size">쿼드 트리에서는 이를 압축하여 간단히 표현할 수 있다.</p>



<p class="has-medium-font-size">주어진 영상이 모두 0으로만 되어 있으면 압축 결과는 &#8220;0&#8221;이 되고, 모두 1로만 되어 있으면 압축 결과는 &#8220;1&#8221;이 된다. </p>



<p class="has-medium-font-size">만약 0과 1이 섞여 있으면 전체를 한 번에 나타내지를 못하고, </p>



<p class="has-medium-font-size">왼쪽 위, 오른쪽 위, 왼쪽 아래, 오른쪽 아래, 이렇게 4개의 영상으로 나누어 압축하게 되며, </p>



<p class="has-medium-font-size">이 4개의 영역을 압축한 결과를 차례대로 괄호 안에 묶어서 표현한다</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="876" height="361" src="https://lycos7560.com/wp-content/uploads/2023/02/image-71.png" alt="" class="wp-image-33182" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-71.png 876w, https://lycos7560.com/wp-content/uploads/2023/02/image-71-300x124.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-71-768x316.png 768w" sizes="(max-width: 876px) 100vw, 876px" /></figure>



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



<p class="has-medium-font-size">위 그림에서 왼쪽의 영상은 오른쪽의 배열과 같이 숫자로 주어지며, </p>



<p class="has-medium-font-size">이 영상을 쿼드 트리 구조를 이용하여 압축하면 &#8220;<code>(0(0011)(0(0111)01)1)</code>&#8220;로 표현된다. </p>



<p class="has-medium-font-size">N ×N 크기의 영상이 주어질 때, 이 영상을 압축한 결과를 출력하는 프로그램을 작성하시오.</p>



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



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



<p class="has-medium-font-size">첫째 줄에는 영상의 크기를 나타내는 숫자 N 이 주어진다. </p>



<p class="has-medium-font-size">N 은 언제나 2의 제곱수로 주어지며, 1 ≤ N ≤ 64의 범위를 가진다. </p>



<p class="has-medium-font-size">두 번째 줄부터는 길이 N의 문자열이 N개 들어온다. </p>



<p class="has-medium-font-size">각 문자열은 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
11110000
11110000
00011100
00011100
11110000
11110000
11110011
11110011</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="">((110(0101))(0010)1(0001))</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/kofgb" target="_blank" rel="noreferrer noopener">kofgb</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/24" target="_blank" rel="noreferrer noopener">분할 정복</a></li>



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



<p class="has-medium-font-size">이렇게 4개의 영상으로 나누어서 다시 확인한다. (분할 정복)</p>



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

using namespace std;

int N;

char map[64][64];

string result;

void DivisionalConquest(int x, int y, int w)
{
	bool check = true;
	for (int i = 0; i &lt; w ; i++) {
		for (int j = 0; j &lt; w; j++) {
			if (map[x][y] != map[x + i][y + j]) check = false;
		}
		if (!check) break;
	}

	if (check) {
		result.push_back(map[x][y]);
		return;
	}
	else if (w == 1) {
		for (int i = 0; i &lt; w; i++) {
			for (int j = 0; j &lt; w; j++) {
				result.push_back(map[x + i][y + j]);
			}
		}

		return;
	}

	result.push_back('(');
	DivisionalConquest(x , y, w / 2);
	DivisionalConquest(x , y + w / 2, w / 2);
	DivisionalConquest(x + w / 2, y, w / 2);
	DivisionalConquest(x + w / 2, y + w / 2, w / 2);
	result.push_back(')');


}

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

	cin >> N;

	string str;

	for (int i = 0; i &lt; N; i++) {
		cin >> str;
		for (int j = 0; j &lt; str.length(); j++) {
			map[i][j] = str[j];
		}
	}

	DivisionalConquest(0, 0, N);

	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="1243" height="115" src="https://lycos7560.com/wp-content/uploads/2023/02/image-72.png" alt="" class="wp-image-33189" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-72.png 1243w, https://lycos7560.com/wp-content/uploads/2023/02/image-72-300x28.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-72-768x71.png 768w" sizes="(max-width: 1243px) 100vw, 1243px" /></figure>



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



<h1 class="wp-block-heading">추가 반례</h1>



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



<div style="height:40px" 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="">8
11110000
11110000
00011100
00011100
11110000
11110000
11110011
11110011</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="">((110(0101))(0010)1(0001))</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="">16
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000</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="">((1010)(1010)(1010)(1010))</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="">32
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000</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="">(((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010)))</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="">64
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000</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="">((((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010)))(((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010)))(((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010)))(((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))))</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="">1</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="">1</pre>



<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-1992%eb%b2%88-%ec%bf%bc%eb%93%9c%ed%8a%b8%eb%a6%ac-c-divideandconquer-baekjoon/33181/">백준 1992번 (쿼드트리, C++, DivideAndConquer) / 추가 반례 [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-1992%eb%b2%88-%ec%bf%bc%eb%93%9c%ed%8a%b8%eb%a6%ac-c-divideandconquer-baekjoon/33181/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 10815번 (숫자 카드, C++, Binary Search) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10815%eb%b2%88-%ec%88%ab%ec%9e%90-%ec%b9%b4%eb%93%9c-c-binary-search-baekjoon/5862/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10815%eb%b2%88-%ec%88%ab%ec%9e%90-%ec%b9%b4%eb%93%9c-c-binary-search-baekjoon/5862/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 31 Jan 2023 13:12:25 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[10815]]></category>
		<category><![CDATA[10815번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[Binary]]></category>
		<category><![CDATA[Binary Search]]></category>
		<category><![CDATA[BinarySearch]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Recursive]]></category>
		<category><![CDATA[Search]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 10815]]></category>
		<category><![CDATA[백준 10815번]]></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=5862</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 10815번 '숫자 카드' 문제에 대한 글입니다. 'Binary Search' 를 이용하여 해결하였습니다. (This is an article about the 'number card' problem in BAEKJOON 10815. I solved it using 'Binary Search'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10815%eb%b2%88-%ec%88%ab%ec%9e%90-%ec%b9%b4%eb%93%9c-c-binary-search-baekjoon/5862/">백준 10815번 (숫자 카드, C++, Binary Search) [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/10815" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/10815</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">256 MB</td><td class="has-text-align-left" data-align="left">70735</td><td class="has-text-align-left" data-align="left">32252</td><td class="has-text-align-left" data-align="left">23137</td><td class="has-text-align-left" data-align="left">44.720%</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">상근이는 숫자 카드 N개를 가지고 있다.&nbsp;</p>



<p class="has-medium-font-size">정수 M개가 주어졌을 때, </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(1 ≤ N ≤ 500,000)이 주어진다. </p>



<p class="has-medium-font-size">둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. </p>



<p class="has-medium-font-size">숫자 카드에 적혀있는 수는&nbsp;-10,000,000보다 크거나 같고, 10,000,000보다 작거나 같다. </p>



<p class="has-medium-font-size">두 숫자&nbsp;카드에 같은 수가 적혀있는 경우는 없다.</p>



<p class="has-medium-font-size">셋째 줄에는 M(1 ≤ M ≤ 500,000)이 주어진다. </p>



<p class="has-medium-font-size">넷째 줄에는 상근이가 가지고 있는 숫자 카드인지 아닌지를 구해야 할 M개의 정수가 주어지며, </p>



<p class="has-medium-font-size">이 수는 공백으로 구분되어져 있다. 이 수도&nbsp;-10,000,000보다 크거나 같고, 10,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">첫째 줄에 입력으로 주어진 M개의 수에 대해서, </p>



<p class="has-medium-font-size">각&nbsp;수가 적힌 숫자 카드를&nbsp;상근이가 가지고 있으면 1을, 아니면 0을 공백으로 구분해 출력한다.</p>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5
6 3 2 10 -10
8
10 9 -5 2 3 4 5 -10</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="">1 0 0 1 1 0 0 1</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/cko301" target="_blank" rel="noreferrer noopener">cko301</a>,&nbsp;<a href="https://www.acmicpc.net/user/eric00513" target="_blank" rel="noreferrer noopener">eric00513</a>,&nbsp;<a href="https://www.acmicpc.net/user/lety" target="_blank" rel="noreferrer noopener">lety</a>,&nbsp;<a href="https://www.acmicpc.net/user/mystika" target="_blank" rel="noreferrer noopener">mystika</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/175" target="_blank" rel="noreferrer noopener">자료 구조</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/97" target="_blank" rel="noreferrer noopener">정렬</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/12" 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-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/01/image-53.png" alt="" class="wp-image-5867" width="626" height="463" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-53.png 820w, https://lycos7560.com/wp-content/uploads/2023/01/image-53-300x222.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-53-768x568.png 768w" sizes="(max-width: 626px) 100vw, 626px" /></figure>



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



<p class="has-medium-font-size">순회 형식으로 구현하면 숫자 하나를 확인할때 마다 500,000번의 연산이 필요하다. (시간 초과)</p>



<p class="has-medium-font-size">순회로 확인하는 방법보다 더 빠른 탐색 방법이 필요한데 </p>



<p class="has-medium-font-size">이럴 때 binary search를 이용하여 탐색의 시간 복잡도를 O(logN)으로 만들 수 있다.</p>



<p class="has-medium-font-size">코드는 재귀적으로 작성하였고 해설 참고하면 쉽게 이해가 가능하다.</p>



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



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



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



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

using namespace std;

constexpr int MAX = 500000;

int arr[MAX];

int N , M, target;

// 이분 탐색 함수
bool BinarySearch(int tArr[MAX], int start, int end, int target)
{
	if (start > end) return false; // 만족하는 결과가 없다 false return

	int mid = (start + end) / 2; // 중간 값을 찾아준다.

	if (arr[mid] == target)	return true; // 만족하는 결과!! true return

	// 찾는 수가 더 작다면, 검사 범위를 더 작게해서 다시 이분탐색 // 결과가 나오면 return
	// 찾는 수가 더 크면, 검사 범위를 더 크게해서 다시 이분탐색 // 결과가 나오면 return
	if (arr[mid] > target) return BinarySearch(arr, start, mid - 1, target);
	else return BinarySearch(arr, mid + 1, end, target);
}

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

	cin >> N;

	for (int i = 0; i &lt; N; i++) cin >> arr[i];
	
	// 이분 탐색을 위한 오름차순 정렬을 수행한다.
	sort(arr, arr + N);

	// 탐색할 숫자의 개수를 입력받는다.
	cin >> M;

	for (int i = 0; i &lt; M; i++) {
		
		cin >> target;
		
		// 이진 탐색 후 출력
		cout &lt;&lt; BinarySearch(arr, 0, N - 1, target) &lt;&lt; "\n";

	}

	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="1037" height="99" src="https://lycos7560.com/wp-content/uploads/2023/01/image-52.png" alt="" class="wp-image-5863" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-52.png 1037w, https://lycos7560.com/wp-content/uploads/2023/01/image-52-300x29.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-52-768x73.png 768w" sizes="(max-width: 1037px) 100vw, 1037px" /></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-10815%eb%b2%88-%ec%88%ab%ec%9e%90-%ec%b9%b4%eb%93%9c-c-binary-search-baekjoon/5862/">백준 10815번 (숫자 카드, C++, Binary Search) [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-10815%eb%b2%88-%ec%88%ab%ec%9e%90-%ec%b9%b4%eb%93%9c-c-binary-search-baekjoon/5862/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1780번 (종이의 개수, C++, DivideAndConquer) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1780%eb%b2%88-%ec%a2%85%ec%9d%b4%ec%9d%98-%ea%b0%9c%ec%88%98-c-divideandconquer-baekjoon/5718/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1780%eb%b2%88-%ec%a2%85%ec%9d%b4%ec%9d%98-%ea%b0%9c%ec%88%98-c-divideandconquer-baekjoon/5718/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 29 Jan 2023 07:52:12 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1780]]></category>
		<category><![CDATA[1780번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cin.tie(NULL)]]></category>
		<category><![CDATA[cout.tie(NULL)]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DivideAndConquer]]></category>
		<category><![CDATA[divisionconquest]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></category>
		<category><![CDATA[Recursive]]></category>
		<category><![CDATA[std]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1780]]></category>
		<category><![CDATA[백준 1780번]]></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=5718</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1780번 "종이의 개수" 문제에 대한 글입니다. 재귀를 이용한 "분할정복" 알고리즘을 이용하여 해결하였습니다. (This is an article on the issue of "Number of Paper" in BAEKJOON 1780. It was solved using a "divisional conquest" algorithm using recursive.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1780%eb%b2%88-%ec%a2%85%ec%9d%b4%ec%9d%98-%ea%b0%9c%ec%88%98-c-divideandconquer-baekjoon/5718/">백준 1780번 (종이의 개수, C++, DivideAndConquer) [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/1780" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1780</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">256 MB</td><td class="has-text-align-left" data-align="left">35301</td><td class="has-text-align-left" data-align="left">20969</td><td class="has-text-align-left" data-align="left">15720</td><td class="has-text-align-left" data-align="left">58.541%</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크기의 행렬로 표현되는 종이가 있다. </p>



<p class="has-medium-font-size">종이의 각 칸에는 -1, 0, 1 중 하나가 저장되어 있다. </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">1. 만약 종이가 모두 같은 수로 되어 있다면 이 종이를 그대로 사용한다.</p>



<p class="has-medium-font-size">2. (1)이 아닌 경우에는 종이를 같은 크기의 종이 9개로 자르고, 각각의 잘린 종이에 대해서 (1)의 과정을 반복한다.</p>



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



<p class="has-medium-font-size">이와 같이 종이를 잘랐을 때, -1로만 채워진 종이의 개수, 0으로만 채워진 종이의 개수, </p>



<p class="has-medium-font-size">1로만 채워진 종이의 개수를 구해내는 프로그램을 작성하시오.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 N(1 ≤ N ≤ 3<sup>7</sup>, N은 3<sup>k</sup>&nbsp;꼴)이 주어진다. </p>



<p class="has-medium-font-size">다음 N개의 줄에는 N개의 정수로 행렬이 주어진다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 -1로만 채워진 종이의 개수를, 둘째 줄에 0으로만 채워진 종이의 개수를, </p>



<p class="has-medium-font-size">셋째 줄에 1로만 채워진 종이의 개수를 출력한다.</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="">9
0 0 0 1 1 1 -1 -1 -1
0 0 0 1 1 1 -1 -1 -1
0 0 0 1 1 1 -1 -1 -1
1 1 1 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0
0 1 -1 0 1 -1 0 1 -1
0 -1 1 0 1 -1 0 1 -1
0 1 -1 1 0 -1 0 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="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">10
12
11</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/author5">author5</a></li>



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



<li>잘못된 데이터를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/tncks0121">tncks0121</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/24">분할 정복</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/62">재귀</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">아니면 9부분으로 나눈 후에 다시 확인 </p>



<p class="has-medium-font-size">길이가 1 (3^0)이 될때 까지 해당 로직을 반복한다.</p>



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

using namespace std;

constexpr int MAX = 2187;

int map[MAX][MAX];

int N;

// 0 = 0 / 1 = 1 / -1 = 2
int result[3];

void ConquestDivison(int x, int y, int w)
{
	// 종이의 길이가 1(3^0) 이라면 해당 종이의 카운트를 증가시켜 줍니다.
	if (w == 0) { 
		if (map[x][y] == -1) result[2]++;
		else result[map[x][y]]++;
		return;
	}

	int number = map[x][y];
	int temp = pow(3, w);
	bool check = true;
	for (int i = 0; i &lt; temp; i++) {
		for (int j = 0; j &lt; temp; j++) {
			// 모든 부분이 서로 같은지 체크합니다.
			// 다르다면 빠져나가고 마킹해줍니다.
			if (number == map[x + i][y + j]) { continue; }
			else {
				check = false;
				break;
			}
		}
		if (!check) break;
	}

	if (check) { // 모든 부분이 같다면 해강 종이의 카운트를 올려줍니다.
		if (number == -1) result[2]++;
		else result[map[x][y]]++;
		return;
	}
	
	int temp2 = pow(3, w - 1);

	// 분할 정복 9등분
	ConquestDivison(x              , y              , w - 1);
	ConquestDivison(x              , y + temp2      , w - 1);
	ConquestDivison(x              , y + 2 * (temp2), w - 1);

	ConquestDivison(x + temp2	   , y				, w - 1);
	ConquestDivison(x + temp2	   , y + temp2		, w - 1);
	ConquestDivison(x + temp2	   , y + 2 * (temp2), w - 1);

	ConquestDivison(x + 2 * (temp2), y	            , w - 1);
	ConquestDivison(x + 2 * (temp2), y + temp2	    , w - 1);
	ConquestDivison(x + 2 * (temp2), y + 2 * (temp2), w - 1);
}


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

	cin >> N;

	// 문제를 입력받습니다.
	for (int i = 0; i &lt; N; i++) {
		for (int j = 0; j &lt; N; j++) {
			cin >> map[i][j];
		}
	}

	// N이 3의 몇승인지 확인합니다.
	int k = 0;
	int temp = N;
	while (temp != 1) {
		temp /= 3;
		k++;
	}
	
	ConquestDivison(0, 0, k);

	cout &lt;&lt; result[2] &lt;&lt; "\n" &lt;&lt; result[0] &lt;&lt; "\n" &lt;&lt; result[1];

	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="1038" height="145" src="https://lycos7560.com/wp-content/uploads/2023/01/image-37.png" alt="" class="wp-image-5722" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-37.png 1038w, https://lycos7560.com/wp-content/uploads/2023/01/image-37-300x42.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-37-768x107.png 768w" sizes="(max-width: 1038px) 100vw, 1038px" /></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-1780%eb%b2%88-%ec%a2%85%ec%9d%b4%ec%9d%98-%ea%b0%9c%ec%88%98-c-divideandconquer-baekjoon/5718/">백준 1780번 (종이의 개수, C++, DivideAndConquer) [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-1780%eb%b2%88-%ec%a2%85%ec%9d%b4%ec%9d%98-%ea%b0%9c%ec%88%98-c-divideandconquer-baekjoon/5718/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 11403번 (경로 찾기, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11403%eb%b2%88-%ea%b2%bd%eb%a1%9c-%ec%b0%be%ea%b8%b0-c-baekjoon/5674/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11403%eb%b2%88-%ea%b2%bd%eb%a1%9c-%ec%b0%be%ea%b8%b0-c-baekjoon/5674/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 27 Jan 2023 16:04:07 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[11403]]></category>
		<category><![CDATA[11403번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Recursive]]></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[백준 11403]]></category>
		<category><![CDATA[백준 11403번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[재귀]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5674</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 11403번 '경로 찾기' 문제에 대한 글입니다. 재귀 방식을 이용하여 해결하였습니다. (This is an article about the 'finding route' problem in BAEKJOON 11403. It was resolved using a recursive method.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11403%eb%b2%88-%ea%b2%bd%eb%a1%9c-%ec%b0%be%ea%b8%b0-c-baekjoon/5674/">백준 11403번 (경로 찾기, 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/11403" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/11403</a></p>



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



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">1 초</td><td class="has-text-align-left" data-align="left">256 MB</td><td class="has-text-align-left" data-align="left">37990</td><td class="has-text-align-left" data-align="left">22505</td><td class="has-text-align-left" data-align="left">16504</td><td class="has-text-align-left" data-align="left">58.953%</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">가중치 없는 방향 그래프 G가 주어졌을 때, 모든 정점 (i, j)에 대해서, </p>



<p class="has-medium-font-size">i에서 j로 가는 경로가 있는지 없는지 구하는 프로그램을 작성하시오.</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 (1 ≤ N ≤ 100)이 주어진다. </p>



<p class="has-medium-font-size">둘째 줄부터 N개 줄에는 그래프의 인접 행렬이 주어진다. </p>



<p class="has-medium-font-size">i번째 줄의 j번째 숫자가 1인 경우에는 i에서 j로 가는 간선이 존재한다는 뜻이고, 0인 경우는 없다는 뜻이다. </p>



<p class="has-medium-font-size">i번째 줄의 i번째 숫자는 항상 0이다.</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개의 줄에 걸쳐서 문제의 정답을 인접행렬 형식으로 출력한다.</p>



<p class="has-medium-font-size"> 정점 i에서 j로 가는 경로가 있으면 i번째 줄의 j번째 숫자를 1로, 없으면 0으로 출력해야 한다.</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 1 0
0 0 1
1 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="">1 1 1
1 1 1
1 1 1</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="">7
0 0 0 1 0 0 0
0 0 0 0 0 0 1
0 0 0 0 0 0 0
0 0 0 0 1 1 0
1 0 0 0 0 0 0
0 0 0 0 0 0 1
0 0 1 0 0 0 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="">1 0 1 1 1 1 1
0 0 1 0 0 0 1
0 0 0 0 0 0 0
1 0 1 1 1 1 1
1 0 1 1 1 1 1
0 0 1 0 0 0 1
0 0 1 0 0 0 0</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
0 0 0 1 0 0 0
0 0 0 0 0 0 1
0 0 0 0 0 0 0
0 0 0 0 1 1 0
1 0 0 0 0 0 0
0 0 0 0 0 0 1
0 0 1 0 0 0 0</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="">1 0 1 1 1 1 1
0 0 1 0 0 0 1
0 0 0 0 0 0 0
1 0 1 1 1 1 1
1 0 1 1 1 1 1
0 0 1 0 0 0 1
0 0 1 0 0 0 0</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>문제를 만든 사람: <a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/degurii" target="_blank" rel="noreferrer noopener">degurii</a></li>
</ul>



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



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



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



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



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

using namespace std;

constexpr int MAXN = 101;

bool map[MAXN][MAXN];
bool mapcheck[MAXN][MAXN];

int N, temp;

void check(int start, int end)
{
    mapcheck[start][end] = true;
    map[start][end] = true;

    for (int i = 1; i &lt;= N; i++) {
        if (map[end][i] &amp;&amp; !mapcheck[start][i]) {
            check(start, i);
        } 
    } 
}

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

    cin >> N;

    for (int i = 1; i &lt;= N; i++) {
        for (int j = 1; j &lt;= N; j++) {
            cin >> map[i][j];
        }
    }

    for (int i = 1; i &lt;= N; i++) {
        for (int j = 1; j &lt;= N; j++) {
            if (map[i][j] == true &amp;&amp; mapcheck[i][j] != true) {
                mapcheck[i][j] = true;
                check(i, j);
            }
        }
    }

    for (int i = 1; i &lt;= N; i++) {
        for (int j = 1; j &lt;= N; j++) {
            cout &lt;&lt; map[i][j] &lt;&lt; " ";
        }
        cout &lt;&lt; "\n";
    }

	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="1245" height="116" src="https://lycos7560.com/wp-content/uploads/2023/01/image-29.png" alt="" class="wp-image-5675" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-29.png 1245w, https://lycos7560.com/wp-content/uploads/2023/01/image-29-300x28.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-29-768x72.png 768w" sizes="(max-width: 1245px) 100vw, 1245px" /></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-11403%eb%b2%88-%ea%b2%bd%eb%a1%9c-%ec%b0%be%ea%b8%b0-c-baekjoon/5674/">백준 11403번 (경로 찾기, 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-11403%eb%b2%88-%ea%b2%bd%eb%a1%9c-%ec%b0%be%ea%b8%b0-c-baekjoon/5674/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
