<?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/%EA%B8%B0%EB%B3%B8/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Fri, 14 Jul 2023 22:24:32 +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>알고리즘 – 비둘기 집의 원리 (Pigeonhole Principle)</title>
		<link>https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%eb%b9%84%eb%91%98%ea%b8%b0-%ec%a7%91%ec%9d%98-%ec%9b%90%eb%a6%ac-pigeonhole-principle/36080/</link>
					<comments>https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%eb%b9%84%eb%91%98%ea%b8%b0-%ec%a7%91%ec%9d%98-%ec%9b%90%eb%a6%ac-pigeonhole-principle/36080/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 14 Jul 2023 22:24:30 +0000</pubDate>
				<category><![CDATA[기타]]></category>
		<category><![CDATA[Pigeonhole]]></category>
		<category><![CDATA[Pigeonhole Principle]]></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>
		<guid isPermaLink="false">https://lycos7560.com/?p=36080</guid>

					<description><![CDATA[<p>비둘기 집의 원리에 대한 블로그 게시글입니다. (A blog post about the principles of pigeon houses.)</p>
<p>The post <a href="https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%eb%b9%84%eb%91%98%ea%b8%b0-%ec%a7%91%ec%9d%98-%ec%9b%90%eb%a6%ac-pigeonhole-principle/36080/">알고리즘 – 비둘기 집의 원리 (Pigeonhole Principle)</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-59188d43      "
					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><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#비둘기집의-원리의-일반화" class="uagb-toc-link__trigger">비둘기집의 원리의 일반화</a><li 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 has-large-font-size">비둘기 집의 원리</h1>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>



<p><em>n</em>+1개의 물건을<em> n</em>개의 상자에 넣은 경우, 최소한 한 상자에는 그 물건이 반드시 두 개 이상 들어있다는 원리를 말한다. </p>



<p>보통 비둘기와 비둘기집의 형태로 비유되어 쓰이기 때문에, 비둘기 집의 원리라고 불린다.</p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="780" height="420" src="https://lycos7560.com/wp-content/uploads/2023/07/image-34.png" alt="" class="wp-image-36084" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-34.png 780w, https://lycos7560.com/wp-content/uploads/2023/07/image-34-300x162.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-34-768x414.png 768w" sizes="(max-width: 780px) 100vw, 780px" /></figure>



<p>비둘기가 10마리, 집이 9개라면 한마리가 남는다.</p>



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



<h2 class="wp-block-heading has-large-font-size">증명</h2>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>



<p>간단한 귀류법으로 증명할 수 있다. </p>



<p>모든 비둘기가 집에 들어간다는 가정 하에</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" alt="n">개의 비둘기집과 <img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/2a135e65a42f2d73cccbfc4569523996ca0036f1" alt="n+1">마리의 비둘기가 있다고 가정한다.<br>만약 각 비둘기집에 한 마리 이하의 비둘기만 들어 있다면, 전체 비둘기집에는 많아야 <img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" alt="n">마리의 비둘기가 존재한다. <br>그런데 비둘기는 모두 <img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/2a135e65a42f2d73cccbfc4569523996ca0036f1" alt="n+1">마리이므로, 이것은 모순이다. <br>따라서 어느 비둘기집에는 두 마리 이상의 비둘기가 있다.</p>
</blockquote>



<p>이 증명은 대표적인 존재증명이다. </p>



<p>즉, 비둘기가 두 마리 이상 존재하는 집이 정확히 어떤 집인지는 이 증명으로 알아낼 수 없다.</p>



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



<h2 class="wp-block-heading has-large-font-size">비둘기집의 원리의 일반화</h2>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>



<p>일반화된 비둘기집 원리는 다음과 같다.</p>



<p><img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" alt="n">개의 별개의 사물을 <img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" alt="m">개의 용기에 나누어 담으면 적어도 한 개의 용기는 <img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/81e801db1dafe4401bb060b3851dd318595a5bed" alt="\left\lceil {\frac  nm}\right\rceil "> 이상의 사물을 담고 있어야 한다. </p>



<p>(여기서, <img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/5ac7f37c8288700904b4a22a2f7c94d45ba917de" alt="\lceil x\rceil ">는 <img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/87f9e315fd7e2ba406057a97300593c4802b53e4" alt="x">보다 작지 않은 최소 정수를 의미한다.)</p>



<p>확률론적으로 일반화된 비둘기집 원리는 다음과 같다.</p>



<p><img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/6dbabfa67f5f4f81ea6c073d5b9d8f05df383972" alt="{\frac  1m}">의 균일한 확률로 <img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" alt="n">개의 비둘기를 무작위로 <img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" alt="m">개의 비둘기집에 넣었다면 확률적으로 적어도 하나의 비둘기집에 두마리 이상의 비둘기가 들어가게 된다.</p>



<p><img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/5595f881d4015ee09def36a7482be8661865b053" alt="1-{\frac  {m!}{(m-n)!\;m^{n}}}=1-{\frac  {m(m-1)(m-2)\cdots (m-n+1)}{m^{n}}}\!"></p>



<p><img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/26819344e55f5e671c76c07c18eb4291fcec85ae" alt="n=0"> 인 경우와, <img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/d9ec7e1edc2e6d98f5aec2a39ae5f1c99d1e1425" alt="n=1">인 경우(단, <img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/501173910e6da8425b4e9d44a4e8643620bc2464" alt="m&gt;0">)에 확률은 0인데, 달리 말하면 비둘기가 한마리 밖에 없다고 하면, </p>



<p>충돌(한 비둘기집에 두 마리 이상의 비둘기가 들어가는 일)이 일어날 수 없다는 것이다. </p>



<p><img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/e64e2a4a5b6cb58f1553c6a65551b4898bb82403" alt="n&gt;m"> (비둘기가 비둘기집보다 많다)이라면 확률은 1이 되고 이런 경우에는 보통의 비둘기집 원리와 같은 일이 일어난다. </p>



<p>그러나 비둘기의 수가 비둘기집의 수를 초과하지 않는다 하더라도 (<img decoding="async" src="https://wikimedia.org/api/rest_v1/media/math/render/svg/1be80a749be067190db51891139a12d4886fc054" alt="n\leq m">), 비둘기 분배의 무작위적인 성질에 의하여 종종 상당한 확률로 충돌이 일어난다. </p>



<p>예를 들어, 2마리의 비둘기가 무작위로 4개의 비둘기집에 분배된다면, 25%의 확률로 적어도 하나의 비둘기집에 두마리 이상의 비둘기가 들어가게 될 것이며, </p>



<p>5마리의 비둘기를 10개의 비둘기집에 분배한다면 확률은 69.76%가 되고, 10마리의 비둘기를 20개의 비둘기집에 분배하면 그 확률은 약 93.45%가 된다.</p>



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



<p>출처 : <a href="https://ko.wikipedia.org/wiki/%EB%B9%84%EB%91%98%EA%B8%B0%EC%A7%91_%EC%9B%90%EB%A6%AC" target="_blank" rel="noreferrer noopener">https://ko.wikipedia.org/wiki/%EB%B9%84%EB%91%98%EA%B8%B0%EC%A7%91_%EC%9B%90%EB%A6%AC</a></p>



<div style="margin-top:0;margin-bottom:0;height:150px" aria-hidden="true" class="wp-block-spacer"></div>



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



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>



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



<p>백준 20529번 가장 가까운 세 사람의 심리적 거리</p>



<p><a href="https://www.acmicpc.net/problem/20529">https://www.acmicpc.net/problem/20529</a></p>



<figure class="wp-block-embed is-type-wp-embed is-provider-어제와-내일의-나-그-사이의-이야기 wp-block-embed-어제와-내일의-나-그-사이의-이야기"><div class="wp-block-embed__wrapper">
<blockquote class="wp-embedded-content" data-secret="CODHwoEfpQ"><a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-20529%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b0%80%ea%b9%8c%ec%9a%b4-%ec%84%b8-%ec%82%ac%eb%9e%8c%ec%9d%98-%ec%8b%ac%eb%a6%ac%ec%a0%81-%ea%b1%b0%eb%a6%ac-c-baekjoon/36060/">백준 20529번 (가장 가까운 세 사람의 심리적 거리, C++) [BAEKJOON]</a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  title="&#8220;백준 20529번 (가장 가까운 세 사람의 심리적 거리, C++) [BAEKJOON]&#8221; &#8212; 어제와 내일의 나 그 사이의 이야기" src="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-20529%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b0%80%ea%b9%8c%ec%9a%b4-%ec%84%b8-%ec%82%ac%eb%9e%8c%ec%9d%98-%ec%8b%ac%eb%a6%ac%ec%a0%81-%ea%b1%b0%eb%a6%ac-c-baekjoon/36060/embed/#?secret=3GS4lY6rks#?secret=CODHwoEfpQ" data-secret="CODHwoEfpQ" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>



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



<p>백준 비둘기 집의 원리 관련 문제들</p>



<p><a href="https://www.acmicpc.net/problemset?sort=ac_desc&amp;algo=189">https://www.acmicpc.net/problemset?sort=ac_desc&amp;algo=189</a></p>



<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/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%eb%b9%84%eb%91%98%ea%b8%b0-%ec%a7%91%ec%9d%98-%ec%9b%90%eb%a6%ac-pigeonhole-principle/36080/">알고리즘 – 비둘기 집의 원리 (Pigeonhole Principle)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%eb%b9%84%eb%91%98%ea%b8%b0-%ec%a7%91%ec%9d%98-%ec%9b%90%eb%a6%ac-pigeonhole-principle/36080/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 121690 4번 보물 지도 [PCCP 모의고사 2회]</title>
		<link>https://lycos7560.com/cpp/programmers/programmers-121690-4%eb%b2%88-%eb%b3%b4%eb%ac%bc-%ec%a7%80%eb%8f%84-pccp-%eb%aa%a8%ec%9d%98%ea%b3%a0%ec%82%ac-2%ed%9a%8c/35629/</link>
					<comments>https://lycos7560.com/cpp/programmers/programmers-121690-4%eb%b2%88-%eb%b3%b4%eb%ac%bc-%ec%a7%80%eb%8f%84-pccp-%eb%aa%a8%ec%9d%98%ea%b3%a0%ec%82%ac-2%ed%9a%8c/35629/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 02 Jul 2023 22:15:56 +0000</pubDate>
				<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[[PCCP 모의고사 2]]]></category>
		<category><![CDATA[121690]]></category>
		<category><![CDATA[121690번]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[PCCP]]></category>
		<category><![CDATA[Programmers 121690]]></category>
		<category><![CDATA[Programmers 121690번]]></category>
		<category><![CDATA[Programmers Certified Coding Professional]]></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>
		<category><![CDATA[프로그래머스]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=35629</guid>

					<description><![CDATA[<p>programmers 121690번 '보물 지도' 문제에 대한 글입니다. BFS 탐색을 이용하여 해결하였습니다. (This article is about the problem of 'Treasure Map' in programmers 121690. It was solved using BFS Search.) [PCCP]</p>
<p>The post <a href="https://lycos7560.com/cpp/programmers/programmers-121690-4%eb%b2%88-%eb%b3%b4%eb%ac%bc-%ec%a7%80%eb%8f%84-pccp-%eb%aa%a8%ec%9d%98%ea%b3%a0%ec%82%ac-2%ed%9a%8c/35629/">Programmers 121690 4번 보물 지도 [PCCP 모의고사 2회]</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-8bbbaa18      "
					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">보물 지도</h1>



<p class="has-small-font-size"><a href="https://school.programmers.co.kr/learn/courses/15009/lessons/121690" target="_blank" rel="noreferrer noopener">https://school.programmers.co.kr/learn/courses/15009/lessons/121690</a></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>보물지도는 가로 길이가 <code>n</code>, 세로 길이가 <code>m</code>인 직사각형 모양입니다.</p>



<p>맨 왼쪽 아래 칸의 좌표를 (1, 1)으로, 맨 오른쪽 위 칸의 좌표를 (n, m)으로 나타냈을 때, 보물은 (n, m) 좌표에 묻혀있습니다. </p>



<p>또한, 일부 칸에는 함정이 있으며, 해당 칸으로는 지나갈 수 없습니다.</p>



<p>진수는 처음에 (1, 1) 좌표에서 출발해 보물이 있는 칸으로 이동하려 합니다. </p>



<p>이동할 때는 [상,하,좌,우]로 인접한 네 칸 중 한 칸으로 걸어서 이동합니다. </p>



<p>한 칸을 걸어서 이동하는 데 걸리는 시간은 1입니다.</p>



<p>진수는 보물이 위치한 칸으로 수월하게 이동하기 위해 신비로운 신발을 하나 준비했습니다. </p>



<p>이 신발을 신고 뛰면 한 번에 두 칸을 이동할 수 있으며, 함정이 있는 칸도 넘을 수 있습니다. </p>



<p>하지만, 이 신발은 한 번밖에 사용할 수 없습니다. </p>



<p>신비로운 신발을 사용하여 뛰어서 두 칸을 이동하는 시간도 1입니다.</p>



<p>이때 진수가 출발점에서 보물이 위치한 칸으로 이동하는데 필요한 최소 시간을 구해야 합니다.</p>



<p>예를 들어, 진수의 보물지도가 아래 그림과 같을 때, 진수가 걸어서 오른쪽으로 3칸, </p>



<p>걸어서 위쪽으로 3칸 이동하면 6의 시간에 보물이 위치한 칸으로 이동할 수 있습니다. </p>



<p>만약, 오른쪽으로 걸어서 1칸, 위쪽으로 걸어서 1칸, 신비로운 신발을 사용하여 위로 뛰어 2칸, </p>



<p>오른쪽으로 걸어서 2칸 이동한다면 총 5의 시간에 보물이 위치한 칸으로 이동할 수 있으며, </p>



<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="460" height="461" src="https://lycos7560.com/wp-content/uploads/2023/07/image-1.png" alt="" class="wp-image-35631" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-1.png 460w, https://lycos7560.com/wp-content/uploads/2023/07/image-1-300x300.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-1-150x150.png 150w" sizes="(max-width: 460px) 100vw, 460px" /></figure>



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



<p>진수의 보물지도가 표현하는 지역의 가로 길이를 나타내는 정수 <code>n</code>, </p>



<p>세로 길이를 나타내는 정수 <code>m</code>, 함정의 위치를 나타내는 2차원 정수 배열 <code>hole</code>이 주어졌을 때, </p>



<p>진수가 보물이 있는 칸으로 이동하는데 필요한 최소 시간을 return 하는 solution 함수를 완성해주세요. </p>



<p><strong>단, 보물이 있는 칸으로 이동할 수 없다면, -1을 return 해야 합니다.</strong></p>



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



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



<ul class="wp-block-list">
<li>1 ≤ <code>n</code>, <code>m</code> ≤ 1,000
<ul class="wp-block-list">
<li>단,&nbsp;<code>n</code>&nbsp;*&nbsp;<code>m</code>이 3 이상인 경우만 입력으로 주어집니다.</li>
</ul>
</li>



<li>1 ≤ <code>hole</code>의 길이 ≤ <code>n</code> * <code>m</code> &#8211; 2
<ul class="wp-block-list">
<li><code>hole[i]</code>는 [a, b]의 형태이며, (a, b) 칸에 함정이 존재한다는 의미이며, 1 ≤ a ≤&nbsp;<code>n</code>, 1 ≤ b ≤&nbsp;<code>m</code>을 만족합니다.</li>



<li>같은 함정에 대한 정보가 중복해서 들어있지 않습니다.</li>
</ul>
</li>



<li>(1, 1) 칸과 (n, m) 칸은 항상 함정이 없습니다.</li>
</ul>



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



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



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">n</th><th class="has-text-align-left" data-align="left">m</th><th class="has-text-align-left" data-align="left">hole</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">4</td><td class="has-text-align-left" data-align="left">4</td><td class="has-text-align-left" data-align="left">[[2, 3], [3, 3]]</td><td class="has-text-align-left" data-align="left">5</td></tr><tr><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left">4</td><td class="has-text-align-left" data-align="left">[[1, 4], [2, 1], [2, 2], [2, 3], [2, 4], [3, 3], [4, 1], [4, 3], [5, 3]]</td><td class="has-text-align-left" data-align="left">-1</td></tr></tbody></table></figure>



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



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



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



<ul class="wp-block-list">
<li>본문의 예시와 같습니다.</li>
</ul>



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



<ul class="wp-block-list">
<li>보물지도를 그림으로 나타내면 아래와 같으며, 보물이 위치한 칸으로 이동할 수 없습니다. <br>따라서, -1을 return 해야 합니다.</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="619" height="466" src="https://lycos7560.com/wp-content/uploads/2023/07/image-2.png" alt="" class="wp-image-35637" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-2.png 619w, https://lycos7560.com/wp-content/uploads/2023/07/image-2-300x226.png 300w" sizes="(max-width: 619px) 100vw, 619px" /></figure>



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



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



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



<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;string>
#include &lt;vector>
#include &lt;tuple>
#include &lt;queue>
bool _Map[1001][1001];
bool _IsVisted[1001][1001][2]; // 배열의 마지막은 신발의 사용 유무
int _dxdy[8][2] = { {1,0},{0,1},{-1,0},{0,-1}, {2,0},{0,2},{-2,0},{0,-2} };
using namespace std;
int solution(int n, int m, vector&lt;vector&lt;int>> holeVector) {
    int answer = -1;
	for (auto&amp; hole : holeVector)
		_Map[hole[0]][hole[1]] = true;
	tuple&lt;int, int, bool, int> _CntPos = make_tuple(1, 1, true, 0);
	queue&lt;tuple&lt;int, int, bool, int>> _MyQueue;
	_IsVisted[1][1][1] = true;
	_MyQueue.push(_CntPos);
	while (!_MyQueue.empty()) {
		_CntPos = _MyQueue.front();
		_MyQueue.pop();
		int _cntX = get&lt;0>(_CntPos);
		int _cntY = get&lt;1>(_CntPos);
		bool _shoes = get&lt;2>(_CntPos);
		int _cnt = get&lt;3>(_CntPos);	

		// 목적지에 도착
		if (_cntX == n &amp;&amp; _cntY == m) {
				answer = _cnt;
				break;
		}

		// 총 8가지의 경우를 탐색
		// 0 ~ 3 상,하,좌,우
		// 4 ~ 7 신발을 사용하여 상,하,좌,우를 2칸씩 이동
		// 꼭 구멍이 있어야 신발을 사용하는 것이 아니다.
		for (int i = 0; i &lt; 8; i++) {
			if (!_shoes &amp;&amp; i >= 4) break;
			int _dx = _cntX + _dxdy[i][0];
			int _dy = _cntY + _dxdy[i][1];
			// 맵의 범위를 벗어나는 경우
			if (_dx > n || _dy > m || _dx &lt;= 0 || _dy &lt;= 0 ) 
				continue;
			// 이동을 하려던 곳이 구멍 &amp;&amp; 신발이 없음 || 이미 방문한 적이 있다.
			if (_Map[_dx][_dy] || _IsVisted[_dx][_dy][_shoes])
				continue;

			if (i >= 4) { // 신발을 사용하여 이동하는 경우
				_MyQueue.push(make_tuple(_dx, _dy, false, _cnt + 1));
				_IsVisted[_dx][_dy][false] = true;
			}
			else { // 신발을 사용하지 않는 경우
				_MyQueue.push(make_tuple(_dx, _dy, _shoes, _cnt + 1));
				_IsVisted[_dx][_dy][_shoes] = true;
			}

		}
	}

	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="554" height="590" src="https://lycos7560.com/wp-content/uploads/2023/07/image-3.png" alt="" class="wp-image-35640" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-3.png 554w, https://lycos7560.com/wp-content/uploads/2023/07/image-3-282x300.png 282w" sizes="(max-width: 554px) 100vw, 554px" /></figure>



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



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/programmers/programmers-121690-4%eb%b2%88-%eb%b3%b4%eb%ac%bc-%ec%a7%80%eb%8f%84-pccp-%eb%aa%a8%ec%9d%98%ea%b3%a0%ec%82%ac-2%ed%9a%8c/35629/">Programmers 121690 4번 보물 지도 [PCCP 모의고사 2회]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/programmers/programmers-121690-4%eb%b2%88-%eb%b3%b4%eb%ac%bc-%ec%a7%80%eb%8f%84-pccp-%eb%aa%a8%ec%9d%98%ea%b3%a0%ec%82%ac-2%ed%9a%8c/35629/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 10474번 (분수좋아해?, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10474%eb%b2%88-%eb%b6%84%ec%88%98%ec%a2%8b%ec%95%84%ed%95%b4-c-baekjoon/35601/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10474%eb%b2%88-%eb%b6%84%ec%88%98%ec%a2%8b%ec%95%84%ed%95%b4-c-baekjoon/35601/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 28 Jun 2023 03:29:03 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[10474]]></category>
		<category><![CDATA[10474번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 10474]]></category>
		<category><![CDATA[백준 10474번]]></category>
		<category><![CDATA[분수좋아해?]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=35601</guid>

					<description><![CDATA[<p>백준 10474번 '분수좋아해?' 문제에 대한 글입니다. 단순한 사칙연산 문제입니다. (This article is about the question of Baekjoon Number 10474 "Do you like fountain?" It's just a four-pronged operation problem.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10474%eb%b2%88-%eb%b6%84%ec%88%98%ec%a2%8b%ec%95%84%ed%95%b4-c-baekjoon/35601/">백준 10474번 (분수좋아해?, 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-97f3a591      "
					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 class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/10474" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/10474</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">256 MB</td><td class="has-text-align-left" data-align="left">3045</td><td class="has-text-align-left" data-align="left">2307</td><td class="has-text-align-left" data-align="left">2153</td><td class="has-text-align-left" data-align="left">77.586%</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>당신은 학생들의 기초수학 학습을 돕는 소프트웨어를 개발하는 팀의 개발자이다. </p>



<p>당신은 가분수를 대분수(?)로 출력하는 부분을 개발해야 한다. </p>



<p>진분수는 분자가 분모보다 작은 분수이다; 대분수는 정수부를 따로 떼어주고 남는 부분을 진분수로 쓰는 기법이다. </p>



<p>예제로, 27/12는 대분수로 2 3/12이다. 기약분수로 만들지 말아야 한다.</p>



<p>(3/12를 1/4로 바꿔 출력하지 마시오.)</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>각각의 테스트 케이스는 [1, 2^31 &#8211; 1]범위의 두 정수가 입력된다. </p>



<p>첫 번째 정수는 분자고 두 번째는 분모이다. </p>



<p>&#8220;0 0&#8221; 입력이 들어오는 라인에서 입력을 종료한다.</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>



<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="">27 12
2460000 98400
3 4000
0 0</pre>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">2 3 / 12
25 0 / 98400
0 3 / 4000</pre>



<div style="height:80px" 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> > <a href="https://www.acmicpc.net/category/7" target="_blank" rel="noreferrer noopener">Regionals</a> > <a href="https://www.acmicpc.net/category/8" target="_blank" rel="noreferrer noopener">North America</a> > <a href="https://www.acmicpc.net/category/305" target="_blank" rel="noreferrer noopener">North America Qualification Contest</a> > <a href="https://www.acmicpc.net/category/detail/1307" target="_blank" rel="noreferrer noopener">ACM-ICPC North America Qualifier 2014</a> F번</p>



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



<li>잘못된 번역을 찾은 사람: <a href="https://www.acmicpc.net/user/veydpz" target="_blank" rel="noreferrer noopener">veydpz</a></li>



<li>문제를 만든 사람:&nbsp;Michael Zmuda</li>
</ul>



<div style="height:40px" 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/124" target="_blank" rel="noreferrer noopener">수학</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/121" 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;
int _A, _B;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	while (true) {
		cin >> _A >> _B;
		if (_A == 0 &amp;&amp; _B == 0) break;
		cout &lt;&lt; _A / _B &lt;&lt; " " &lt;&lt; _A % _B &lt;&lt; " / " &lt;&lt; _B &lt;&lt; "\n";
	}
} </pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1205" height="97" src="https://lycos7560.com/wp-content/uploads/2023/06/image-44.png" alt="" class="wp-image-35604" srcset="https://lycos7560.com/wp-content/uploads/2023/06/image-44.png 1205w, https://lycos7560.com/wp-content/uploads/2023/06/image-44-300x24.png 300w, https://lycos7560.com/wp-content/uploads/2023/06/image-44-768x62.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>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-10474%eb%b2%88-%eb%b6%84%ec%88%98%ec%a2%8b%ec%95%84%ed%95%b4-c-baekjoon/35601/">백준 10474번 (분수좋아해?, 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-10474%eb%b2%88-%eb%b6%84%ec%88%98%ec%a2%8b%ec%95%84%ed%95%b4-c-baekjoon/35601/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2161번 (카드1, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2161%eb%b2%88-%ec%b9%b4%eb%93%9c1-c-baekjoon/35524/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2161%eb%b2%88-%ec%b9%b4%eb%93%9c1-c-baekjoon/35524/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 21 Jun 2023 03:23:46 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2161]]></category>
		<category><![CDATA[2161번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 2161]]></category>
		<category><![CDATA[백준 2161번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[자료 구조]]></category>
		<category><![CDATA[자료구조]]></category>
		<category><![CDATA[카드1]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[큐]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=35524</guid>

					<description><![CDATA[<p>백준 2161번 '카드1' 문제에 대한 글입니다. Queue를 이용한 구현문제입니다. (This is an article about the question of "Card 1" in Baekjoon Number 2161.<br />
It is an implementation problem using Queue.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2161%eb%b2%88-%ec%b9%b4%eb%93%9c1-c-baekjoon/35524/">백준 2161번 (카드1, 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-dbc07632      "
					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="#카드1" class="uagb-toc-link__trigger">카드1</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">카드1</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/2161" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/2161</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">12937</td><td class="has-text-align-left" data-align="left">8539</td><td class="has-text-align-left" data-align="left">7532</td><td class="has-text-align-left" data-align="left">68.698%</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>N장의 카드가 있다. 각각의 카드는 차례로 1부터 N까지의 번호가 붙어 있으며, </p>



<p>1번 카드가 제일 위에, N번 카드가 제일 아래인 상태로 순서대로 카드가 놓여 있다.</p>



<p>이제 다음과 같은 동작을 카드가 한 장 남을 때까지 반복하게 된다. </p>



<p>우선, 제일 위에 있는 카드를 바닥에 버린다. </p>



<p>그 다음, 제일 위에 있는 카드를 제일 아래에 있는 카드 밑으로 옮긴다.</p>



<p>예를 들어 N=4인 경우를 생각해 보자. </p>



<p>카드는 제일 위에서부터 1234 의 순서로 놓여있다. </p>



<p>1을 버리면 234가 남는다. 여기서 2를 제일 아래로 옮기면 342가 된다. </p>



<p>3을 버리면 42가 되고, 4를 밑으로 옮기면 24가 된다. </p>



<p>마지막으로 2를 버리고 나면, 버린 카드들은 순서대로 1 3 2가 되고, 남는 카드는 4가 된다.</p>



<p>N이 주어졌을 때, 버린 카드들을 순서대로 출력하고, </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>첫째 줄에 정수 N(1 ≤ N ≤ 1,000)이 주어진다.</p>



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



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



<p>첫째 줄에 버리는 카드들을 순서대로 출력한다. </p>



<p>제일 마지막에는 남게 되는 카드의 번호를 출력한다.</p>



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



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



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



<div style="height:31px" 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 3 5 7 4 2 6</pre>



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



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



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



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



<li><a href="https://www.acmicpc.net/problem/tag/72" 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>큐를 이용하여 상황을 구현하는 단순한 문제입니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;queue>
using namespace std;
queue&lt;int> _MyQueue;
int _N;
int main()
{
	cin >> _N;
	for (int i = 1; i &lt;= _N; i++)
		_MyQueue.push(i);
	while (true) {
		cout &lt;&lt; _MyQueue.front() &lt;&lt; " ";
		_MyQueue.pop();
		if (_MyQueue.empty())
			break;
		_MyQueue.push(_MyQueue.front());
		_MyQueue.pop();
	}
	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1205" height="95" src="https://lycos7560.com/wp-content/uploads/2023/06/image-36.png" alt="" class="wp-image-35526" srcset="https://lycos7560.com/wp-content/uploads/2023/06/image-36.png 1205w, https://lycos7560.com/wp-content/uploads/2023/06/image-36-300x24.png 300w, https://lycos7560.com/wp-content/uploads/2023/06/image-36-768x61.png 768w" sizes="(max-width: 1205px) 100vw, 1205px" /></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-2161%eb%b2%88-%ec%b9%b4%eb%93%9c1-c-baekjoon/35524/">백준 2161번 (카드1, 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-2161%eb%b2%88-%ec%b9%b4%eb%93%9c1-c-baekjoon/35524/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 9663번 (N-Queen, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9663%eb%b2%88-n-queen-c-baekjoon/34814/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9663%eb%b2%88-n-queen-c-baekjoon/34814/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 19 May 2023 04:37:46 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[<algorithm>]]></category>
		<category><![CDATA[9663]]></category>
		<category><![CDATA[9663번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Backtracking]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[N-Queen]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 9663]]></category>
		<category><![CDATA[백준 9663번]]></category>
		<category><![CDATA[백트레킹]]></category>
		<category><![CDATA[브루트 포스]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34814</guid>

					<description><![CDATA[<p>백준 9663번 'N-Queen' 문제에 대한 글입니다. 백트레킹을 이용하여 해결하였습니다. (This article is about the question of "N-Queen" in Baekjun 9663. It was solved using backtracking.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9663%eb%b2%88-n-queen-c-baekjoon/34814/">백준 9663번 (N-Queen, 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-b04bb7c8      "
					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="#n-queen" class="uagb-toc-link__trigger">N-Queen</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">N-Queen</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/9663" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/9663</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">10 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">91882</td><td class="has-text-align-left" data-align="left">44089</td><td class="has-text-align-left" data-align="left">28607</td><td class="has-text-align-left" data-align="left">46.649%</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">N-Queen 문제는&nbsp;크기가 N × N인 체스판 위에 퀸 N개를&nbsp;서로 공격할 수 없게 놓는&nbsp;문제이다.</p>



<p class="has-medium-font-size">N이 주어졌을 때, 퀸을 놓는 방법의 수를 구하는 프로그램을 작성하시오.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 N이 주어진다. (1 ≤ N &lt; 15)</p>



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



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



<p class="has-medium-font-size">첫째 줄에 퀸 N개를 서로 공격할 수 없게 놓는&nbsp;경우의 수를 출력한다.</p>



<div style="height:62px" 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 17</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="">2</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>문제를 만든 사람:&nbsp;<a href="https://www.acmicpc.net/user/baekjoon">baekjoon</a></li>
</ul>



<div style="height:62px" 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/125">브루트포스 알고리즘</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/5">백트래킹</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 has-large-font-size">통과된 코드</h1>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230519_111808847.jpg" alt="" class="wp-image-34817" width="1139" height="1440" srcset="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230519_111808847.jpg 1519w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230519_111808847-237x300.jpg 237w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230519_111808847-768x971.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230519_111808847-1215x1536.jpg 1215w" sizes="(max-width: 1139px) 100vw, 1139px" /></figure>



<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;cmath>
using namespace std;
constexpr int Max = 15; // 체스판의 최대 
int _N, _Res, _Queen[Max];

bool CheckQueens(int _row)
{
	for (int i = 0; i &lt; _row; i++) {
		// 절대값으로 대각선으로 전부 확인
		if (_Queen[i] == _Queen[_row] || ( abs(_Queen[i] - _Queen[_row]) == abs(i - _row))) {
			return false;
		}
	}
	return true;
}

void BackTracing(int _row) {
	// N번째까지 왔다면 경우의 수 추가
	if (_row == _N) {
		_Res++;
		return; 
	}

	for (int _col = 0; _col &lt; _N; _col++) {
		_Queen[_row] = _col;
		//해당 행이 가능한지 확인한다.
		if (CheckQueens(_row)) 
			BackTracing(_row + 1);
	}
}

int main()
{
	cin >> _N; // 체스판의 크기 입력
	BackTracing(0); // 백트레킹으로 체크
	cout &lt;&lt; _Res;
	return 0;
}</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/05/image-88.png" alt="" class="wp-image-34820" width="904" height="73" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-88.png 1205w, https://lycos7560.com/wp-content/uploads/2023/05/image-88-300x24.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-88-768x62.png 768w" sizes="(max-width: 904px) 100vw, 904px" /></figure>



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



<h1 class="wp-block-heading">더 효율적인 코드</h1>



<p class="has-medium-font-size">DFS 탐색을 이용한 백트레킹</p>



<p class="has-medium-font-size">dy dx를 대각선으로 표현하여 검사</p>



<figure class="wp-block-image size-full"><img decoding="async" width="400" height="396" src="https://lycos7560.com/wp-content/uploads/2023/05/image-90.png" alt="" class="wp-image-34825" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-90.png 400w, https://lycos7560.com/wp-content/uploads/2023/05/image-90-300x297.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-90-150x150.png 150w" sizes="(max-width: 400px) 100vw, 400px" /></figure>



<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 Max = 15;
int _N, _Res;
// 체스판 
bool MapArr[Max];
//체스판의 대각선을 표현하기위한 변수
//대각선은 2N - 1개 필요
bool dx[29], dy[29];

void BackTracking(int level)
{
	if (level == _N) {
		_Res++;
		return;
	}
	for (int i = 0; i &lt; _N; i++) {
		//현재 열, 왼쪽 대각선 및 오른쪽 대각선에 이미 배치된 여왕이 없는지 확인
		// dx, dy는 체스판의 특정한 위치를 나타내는 변수가 아니다.
		// dx, dy를 이용하여 대각선을 추적하는 것
		// 배열의 각 인덱스는 dx대각선을 나타내며 해당 인덱스의 값은 대각선이 여왕에 의해 점유되는지 여부를 나타냅니다. 
		if (!MapArr[i] &amp;&amp; !dx[i - level + _N] &amp;&amp; !dy[i + level]) {
			
			MapArr[i] = dx[i - level + _N] = dy[i + level] = true;
			BackTracking(level + 1);
			MapArr[i] = dx[i - level + _N] = dy[i + level] = false;
		}
	}
}

int main() {
	_Res = 0;
	cin >> _N;
	BackTracking(0);
	cout &lt;&lt; _Res;
}</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="99" src="https://lycos7560.com/wp-content/uploads/2023/05/image-89.png" alt="" class="wp-image-34821" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-89.png 1038w, https://lycos7560.com/wp-content/uploads/2023/05/image-89-300x29.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-89-768x73.png 768w" sizes="(max-width: 1038px) 100vw, 1038px" /></figure>



<p></p>



<p></p>



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



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9663%eb%b2%88-n-queen-c-baekjoon/34814/">백준 9663번 (N-Queen, 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-9663%eb%b2%88-n-queen-c-baekjoon/34814/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2460번 (지능형 기차 2, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2460%eb%b2%88-%ec%a7%80%eb%8a%a5%ed%98%95-%ea%b8%b0%ec%b0%a8-2-c-baekjoon/35424/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2460%eb%b2%88-%ec%a7%80%eb%8a%a5%ed%98%95-%ea%b8%b0%ec%b0%a8-2-c-baekjoon/35424/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 18 May 2023 20:59:40 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2460]]></category>
		<category><![CDATA[2460번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 2460]]></category>
		<category><![CDATA[백준 2460번]]></category>
		<category><![CDATA[사칙연산]]></category>
		<category><![CDATA[수학]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[지능형 기차 2]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=35424</guid>

					<description><![CDATA[<p>백준 2460번 '지능형 기차 2' 문제에 대한 글입니다. 해당 문제는 단순한 사칙연산 구현 문제입니다. (This article is about the question of Baekjoon Number 2460 'Intelligent Train 2'. The problem is four fundamental arithmetic operations implementation problem.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2460%eb%b2%88-%ec%a7%80%eb%8a%a5%ed%98%95-%ea%b8%b0%ec%b0%a8-2-c-baekjoon/35424/">백준 2460번 (지능형 기차 2, 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-072afce6      "
					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="#지능형-기차-2" class="uagb-toc-link__trigger">지능형 기차 2</a></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">지능형 기차 2</h1>



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



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



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



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



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



<p>최근에 개발된 지능형 기차가 1번역(출발역)부터 10번역(종착역)까지 10개의 정차역이 있는 노선에서 운행되고 있다. </p>



<p>이 기차에는 타거나 내리는 사람 수를 자동으로 인식할 수 있는 장치가 있다. </p>



<p>이 장치를 이용하여 출발역에서 종착역까지 가는 도중 기차 안에 사람이 가장 많을 때의 사람 수를 계산하려고 한다. </p>



<p>단, 이 기차를 이용하는 사람들은 질서 의식이 투철하여, 역에서 기차에 탈 때, 내릴 사람이 모두 내린 후에 기차에 탄다고 가정한다.</p>



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



<figure class="wp-block-table"><table><tbody><tr><th class="has-text-align-left" data-align="left">&nbsp;</th><th class="has-text-align-left" data-align="left">내린 사람 수</th><th class="has-text-align-left" data-align="left">탄 사람 수</th></tr><tr><th class="has-text-align-left" data-align="left">1번역(출발역)</th><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">32</td></tr><tr><th class="has-text-align-left" data-align="left">2번역</th><td class="has-text-align-left" data-align="left">3</td><td class="has-text-align-left" data-align="left">13</td></tr><tr><th class="has-text-align-left" data-align="left">3번역</th><td class="has-text-align-left" data-align="left">28</td><td class="has-text-align-left" data-align="left">25</td></tr><tr><th class="has-text-align-left" data-align="left">4번역</th><td class="has-text-align-left" data-align="left">17</td><td class="has-text-align-left" data-align="left">5</td></tr><tr><th class="has-text-align-left" data-align="left">5번역</th><td class="has-text-align-left" data-align="left">21</td><td class="has-text-align-left" data-align="left">20</td></tr><tr><th class="has-text-align-left" data-align="left">6번역</th><td class="has-text-align-left" data-align="left">11</td><td class="has-text-align-left" data-align="left">0</td></tr><tr><th class="has-text-align-left" data-align="left">7번역</th><td class="has-text-align-left" data-align="left">12</td><td class="has-text-align-left" data-align="left">12</td></tr><tr><th class="has-text-align-left" data-align="left">8번역</th><td class="has-text-align-left" data-align="left">4</td><td class="has-text-align-left" data-align="left">2</td></tr><tr><th class="has-text-align-left" data-align="left">9번역</th><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">8</td></tr><tr><th class="has-text-align-left" data-align="left">10번역(종착역)</th><td class="has-text-align-left" data-align="left">21</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>예를 들어, 위와 같은 경우를 살펴보자. </p>



<p>이 경우, 기차 안에 사람이 가장 많은 때는 2번역에서 3명의 사람이 기차에서 내리고, </p>



<p>13명의 사람이 기차에 탔을 때로, 총 42명의 사람이 기차 안에 있다.</p>



<p>이 기차는 다음 조건을 만족하면서 운행된다고 가정한다.</p>



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



<ol class="wp-block-list">
<li>기차는 역 번호 순서대로 운행한다.</li>



<li>출발역에서 내린 사람 수와 종착역에서 탄 사람 수는 0이다.</li>



<li>각 역에서 현재 기차에 있는 사람보다 더 많은 사람이 내리는 경우는 없다.</li>



<li>기차의 정원은 최대 10,000명이고, 정원을 초과하여 타는 경우는 없다.</li>
</ol>



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



<p>10개의 역에 대해 기차에서 내린 사람 수와 탄 사람 수가 주어졌을 때, </p>



<p>기차에 사람이 가장 많을 때의 사람 수를 계산하는 프로그램을 작성하시오.</p>



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



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



<p>각 역에서 내린 사람 수와 탄 사람 수가 빈칸을 사이에 두고 첫째 줄부터 열 번째 줄까지 역 순서대로 한 줄에 하나씩 주어진다. </p>



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



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



<p>첫째 줄에 최대 사람 수를 출력한다. &nbsp;</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="">0 32
3 13
28 25
17 5
21 20
11 0
12 12
4 2
0 8
21 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="">42</pre>



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



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



<p><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a> > <a href="https://www.acmicpc.net/category/55" target="_blank" rel="noreferrer noopener">한국정보올림피아드</a> > <a href="https://www.acmicpc.net/category/57" target="_blank" rel="noreferrer noopener">한국정보올림피아드시․도지역본선</a> > <a href="https://www.acmicpc.net/category/60" target="_blank" rel="noreferrer noopener">지역본선 2011</a> > <a href="https://www.acmicpc.net/category/detail/338" target="_blank" rel="noreferrer noopener">중등부</a> 1번</p>



<ul class="wp-block-list">
<li>문제의 오타를 찾은 사람: <a href="https://www.acmicpc.net/user/eric00513" target="_blank" rel="noreferrer noopener">eric00513</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/124" target="_blank" rel="noreferrer noopener">수학</a></li>



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



<li><a href="https://www.acmicpc.net/problem/tag/121" 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>단순한 사칙연산 문제입니다.</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, _Cnt = 0, _In, _Out;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	for (int i = 0; i &lt; 10; i++) {
		cin >> _Out >> _In;
		_Cnt += _In - _Out;
		_Res = max(_Cnt, _Res);
	}
	cout &lt;&lt; _Res;
	return 0;
}</pre>



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



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



<figure class="wp-block-image size-full"><img decoding="async" width="984" height="99" src="https://lycos7560.com/wp-content/uploads/2023/06/image-27.png" alt="" class="wp-image-35427" srcset="https://lycos7560.com/wp-content/uploads/2023/06/image-27.png 984w, https://lycos7560.com/wp-content/uploads/2023/06/image-27-300x30.png 300w, https://lycos7560.com/wp-content/uploads/2023/06/image-27-768x77.png 768w" sizes="(max-width: 984px) 100vw, 984px" /></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-2460%eb%b2%88-%ec%a7%80%eb%8a%a5%ed%98%95-%ea%b8%b0%ec%b0%a8-2-c-baekjoon/35424/">백준 2460번 (지능형 기차 2, 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-2460%eb%b2%88-%ec%a7%80%eb%8a%a5%ed%98%95-%ea%b8%b0%ec%b0%a8-2-c-baekjoon/35424/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Programmers 72414 광고 삽입 [2021 KAKAO BLIND RECRUITMENT]</title>
		<link>https://lycos7560.com/cpp/programmers/programmers-72414-%ea%b4%91%ea%b3%a0-%ec%82%bd%ec%9e%85-2021-kakao-blind-recruitment/34776/</link>
					<comments>https://lycos7560.com/cpp/programmers/programmers-72414-%ea%b4%91%ea%b3%a0-%ec%82%bd%ec%9e%85-2021-kakao-blind-recruitment/34776/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 14 May 2023 13:39:28 +0000</pubDate>
				<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[[2021 KAKAO BLIND RECRUITMENT]]]></category>
		<category><![CDATA[2021 KAKAO BLIND RECRUITMENT]]></category>
		<category><![CDATA[72414]]></category>
		<category><![CDATA[72414번]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[Programmers 72414]]></category>
		<category><![CDATA[Programmers 72414번]]></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[파싱(parsing)]]></category>
		<category><![CDATA[프로그래머스]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34776</guid>

					<description><![CDATA[<p>Programmers 72414번 '광고 삽입' 문제에 대한 글입니다. (This article is about the 'insert advertisement' problem in Programmers Number 72414.) [2021 KAKAO BLIND RECRUITMENT]</p>
<p>The post <a href="https://lycos7560.com/cpp/programmers/programmers-72414-%ea%b4%91%ea%b3%a0-%ec%82%bd%ec%9e%85-2021-kakao-blind-recruitment/34776/">Programmers 72414 광고 삽입 [2021 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-01c05211      "
					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/72414" target="_blank" rel="noreferrer noopener">https://school.programmers.co.kr/learn/courses/30/lessons/72414</a></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"><code>카카오TV</code>에서 유명한 크리에이터로 활동 중인 <code>죠르디</code>는 환경 단체로부터 </p>



<p class="has-medium-font-size">자신의 가장 인기있는 동영상에 지구온난화의 심각성을 알리기 위한 공익광고를 넣어 달라는 요청을 받았습니다. </p>



<p class="has-medium-font-size">평소에 환경 문제에 관심을 가지고 있던 &#8220;죠르디&#8221;는 요청을 받아들였고 </p>



<p class="has-medium-font-size">광고효과를 높이기 위해 시청자들이 가장 많이 보는 구간에 공익광고를 넣으려고 합니다. </p>



<p class="has-medium-font-size">&#8220;죠르디&#8221;는 시청자들이 해당 동영상의 어떤 구간을 재생했는 지 알 수 있는 재생구간 기록을 구했고, </p>



<p class="has-medium-font-size">해당 기록을 바탕으로 공익광고가 삽입될 최적의 위치를 고를 수 있었습니다.</p>



<p class="has-medium-font-size">참고로 광고는 재생 중인 동영상의 오른쪽 아래에서 원래 영상과 <code>동시에 재생되는</code> PIP(Picture in Picture) 형태로 제공됩니다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="989" height="560" src="https://lycos7560.com/wp-content/uploads/2023/05/image-80.jpg" alt="" class="wp-image-34777" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-80.jpg 989w, https://lycos7560.com/wp-content/uploads/2023/05/image-80-300x170.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-80-768x435.jpg 768w" sizes="(max-width: 989px) 100vw, 989px" /></figure>



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



<p class="has-medium-font-size">다음은 &#8220;죠르디&#8221;가 공익광고가 삽입될 최적의 위치를 고르는 과정을 그림으로 설명한 것입니다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1090" height="355" src="https://lycos7560.com/wp-content/uploads/2023/05/image-80.png" alt="" class="wp-image-34779" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-80.png 1090w, https://lycos7560.com/wp-content/uploads/2023/05/image-80-300x98.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-80-768x250.png 768w" sizes="(max-width: 1090px) 100vw, 1090px" /></figure>



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



<ul class="wp-block-list">
<li>그림의 파란색 선은 광고를 검토 중인 &#8220;죠르디&#8221; 동영상의 전체 재생 구간을 나타냅니다.
<ul class="wp-block-list">
<li>위 그림에서, &#8220;죠르디&#8221; 동영상의 총 재생시간은&nbsp;<code>02시간 03분 55초</code>&nbsp;입니다.</li>
</ul>
</li>



<li>그림의 검은색 선들은 각 시청자들이 &#8220;죠르디&#8221;의 동영상을 재생한 구간의 위치를 표시하고 있습니다.
<ul class="wp-block-list">
<li>검은색 선의 가운데 숫자는 각 재생 기록을 구분하는 ID를 나타냅니다.</li>



<li>검은색 선에 표기된 왼쪽 끝 숫자와 오른쪽 끝 숫자는 시청자들이 재생한 동영상 구간의 시작 시각과 종료 시각을 나타냅니다.</li>



<li>위 그림에서, 3번 재생 기록은 <code>00시 25분 50초</code> 부터 <code>00시 48분 29초</code> 까지 총 <code>00시간 22분 39초</code> 동안 죠르디의 동영상을 재생했습니다.</li>



<li>위 그림에서, 1번 재생 기록은&nbsp;<code>01시 20분 15초</code>&nbsp;부터&nbsp;<code>01시 45분 14초</code>&nbsp;까지 총&nbsp;<code>00시간 24분 59초</code>&nbsp;동안 죠르디의 동영상을 재생했습니다.</li>
</ul>
</li>



<li>그림의 빨간색 선은 &#8220;죠르디&#8221;가 선택한 최적의 공익광고 위치를 나타냅니다.
<ul class="wp-block-list">
<li>만약 공익광고의 재생시간이 <code>00시간 14분 15초</code>라면, 위의 그림처럼 <code>01시 30분 59초</code> 부터 <br><code>01시 45분 14초</code> 까지 공익광고를 삽입하는 것이 가장 좋습니다. 이 구간을 시청한 시청자들의 누적 재생시간이 가장 크기 때문입니다.</li>



<li><code>01시 30분 59초</code> 부터 <code>01시 45분 14초</code> 까지의 누적 재생시간은 다음과 같이 계산됩니다.
<ul class="wp-block-list">
<li><code>01시 30분 59초</code>&nbsp;부터&nbsp;<code>01시 37분 44초</code>&nbsp;까지 : 4번, 1번 재생 기록이 두차례 있으므로 재생시간의 합은&nbsp;<code>00시간 06분 45초</code>&nbsp;X 2 =&nbsp;<code>00시간 13분 30초</code></li>



<li><code>01시 37분 44초</code>&nbsp;부터&nbsp;<code>01시 45분 14초</code>&nbsp;까지 : 4번, 1번, 5번 재생 기록이 세차례 있으므로 재생시간의 합은&nbsp;<code>00시간 07분 30초</code>&nbsp;X 3 =&nbsp;<code>00시간 22분 30초</code></li>



<li>따라서, 이 구간 시청자들의 누적 재생시간은&nbsp;<code>00시간 13분 30초</code>&nbsp;+&nbsp;<code>00시간 22분 30초</code>&nbsp;=&nbsp;<code>00시간 36분 00초</code>입니다.</li>
</ul>
</li>
</ul>
</li>
</ul>



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



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



<p class="has-medium-font-size">&#8220;죠르디&#8221;의 동영상 재생시간 길이 play_time, 공익광고의 재생시간 길이 adv_time, </p>



<p class="has-medium-font-size">시청자들이 해당 동영상을 재생했던 구간 정보 logs가 매개변수로 주어질 때, </p>



<p class="has-medium-font-size">시청자들의 누적 재생시간이 가장 많이 나오는 곳에 공익광고를 삽입하려고 합니다. </p>



<p class="has-medium-font-size">이때, 공익광고가 들어갈 <code>시작 시각</code>을 구해서 return 하도록 solution 함수를 완성해주세요. </p>



<p class="has-medium-font-size">만약, 시청자들의 누적 재생시간이 가장 많은 곳이 여러 곳이라면, </p>



<p class="has-medium-font-size">그 중에서 <code>가장 빠른 시작 시각</code>을 return 하도록 합니다.</p>



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



<h2 class="wp-block-heading"><strong>[제한사항]</strong></h2>



<ul class="wp-block-list">
<li>play_time, adv_time은 길이 8로 고정된 문자열입니다.
<ul class="wp-block-list">
<li>play_time, adv_time은&nbsp;<code>HH:MM:SS</code>&nbsp;형식이며,&nbsp;<code>00:00:01</code>&nbsp;이상&nbsp;<code>99:59:59</code>&nbsp;이하입니다.</li>



<li>즉, 동영상 재생시간과 공익광고 재생시간은&nbsp;<code>00시간 00분 01초</code>&nbsp;이상&nbsp;<code>99시간 59분 59초</code>&nbsp;이하입니다.</li>



<li>공익광고 재생시간은 동영상 재생시간보다 짧거나 같게 주어집니다.</li>
</ul>
</li>



<li>logs는 크기가 1 이상 300,000 이하인 문자열 배열입니다.
<ul class="wp-block-list">
<li>logs 배열의 각 원소는 시청자의 재생 구간을 나타냅니다.</li>



<li>logs 배열의 각 원소는 길이가 17로 고정된 문자열입니다.</li>



<li>logs 배열의 각 원소는 <code>H1:M1:S1-H2:M2:S2</code> 형식입니다.
<ul class="wp-block-list">
<li><code>H1:M1:S1</code>은 동영상이 시작된 시각,&nbsp;<code>H2:M2:S2</code>는 동영상이 종료된 시각을 나타냅니다.</li>



<li><code>H1:M1:S1</code>는&nbsp;<code>H2:M2:S2</code>보다 1초 이상 이전 시각으로 주어집니다.</li>



<li><code>H1:M1:S1</code>와&nbsp;<code>H2:M2:S2</code>는 play_time 이내의 시각입니다.</li>
</ul>
</li>
</ul>
</li>



<li>시간을 나타내는 <code>HH, H1, H2</code>의 범위는 00~99, 분을 나타내는 <code>MM, M1, M2</code>의 범위는 00~59, <br>초를 나타내는 <code>SS, S1, S2</code>의 범위는 00~59까지 사용됩니다. <br>잘못된 시각은 입력으로 주어지지 않습니다. (예: <code>04:60:24</code>, <code>11:12:78</code>, <code>123:12:45</code> 등)</li>



<li>return 값의 형식
<ul class="wp-block-list">
<li>공익광고를 삽입할 시각을&nbsp;<code>HH:MM:SS</code>&nbsp;형식의 8자리 문자열로 반환합니다.</li>
</ul>
</li>
</ul>



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



<h2 class="wp-block-heading"><strong>[입출력 예]</strong></h2>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">play_time</th><th class="has-text-align-left" data-align="left">adv_time</th><th class="has-text-align-left" data-align="left">logs</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"><code>"02:03:55"</code></td><td class="has-text-align-left" data-align="left"><code>"00:14:15"</code></td><td class="has-text-align-left" data-align="left"><code>["01:20:15-01:45:14", "00:40:31-01:00:00", "00:25:50-00:48:29", "01:30:59-01:53:29", "01:37:44-02:02:30"]</code></td><td class="has-text-align-left" data-align="left"><code>"01:30:59"</code></td></tr><tr><td class="has-text-align-left" data-align="left"><code>"99:59:59"</code></td><td class="has-text-align-left" data-align="left"><code>"25:00:00"</code></td><td class="has-text-align-left" data-align="left"><code>["69:59:59-89:59:59", "01:00:00-21:00:00", "79:59:59-99:59:59", "11:00:00-31:00:00"]</code></td><td class="has-text-align-left" data-align="left"><code>"01:00:00"</code></td></tr><tr><td class="has-text-align-left" data-align="left"><code>"50:00:00"</code></td><td class="has-text-align-left" data-align="left"><code>"50:00:00"</code></td><td class="has-text-align-left" data-align="left"><code>["15:36:51-38:21:49", "10:14:18-15:36:51", "38:21:49-42:51:45"]</code></td><td class="has-text-align-left" data-align="left"><code>"00:00:00"</code></td></tr></tbody></table></figure>



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



<h2 class="wp-block-heading"><strong>입출력 예에 대한 설명</strong></h2>



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



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



<p>문제 예시와 같습니다.</p>



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



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



<figure class="wp-block-image size-full"><img decoding="async" width="1094" height="321" src="https://lycos7560.com/wp-content/uploads/2023/05/image-81.png" alt="" class="wp-image-34781" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-81.png 1094w, https://lycos7560.com/wp-content/uploads/2023/05/image-81-300x88.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-81-768x225.png 768w" sizes="(max-width: 1094px) 100vw, 1094px" /></figure>



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



<p class="has-medium-font-size"><code>01:00:00</code>에 공익광고를 삽입하면 <code>26:00:00</code>까지 재생되며, 이곳이 가장 좋은 위치입니다. </p>



<p class="has-medium-font-size">이 구간의 시청자 누적 재생시간은 다음과 같습니다.</p>



<ul class="wp-block-list">
<li><code>01:00:00-11:00:00</code>&nbsp;: 해당 구간이 1회(2번 기록) 재생되었으므로 누적 재생시간은&nbsp;<code>10시간 00분 00초</code>&nbsp;입니다.</li>



<li><code>11:00:00-21:00:00</code>&nbsp;: 해당 구간이 2회(2번, 4번 기록) 재생되었으므로 누적 재생시간은&nbsp;<code>20시간 00분 00초</code>&nbsp;입니다.</li>



<li><code>21:00:00-26:00:00</code>&nbsp;: 해당 구간이 1회(4번 기록) 재생되었으므로 누적 재생시간은&nbsp;<code>05시간 00분 00초</code>&nbsp;입니다.</li>



<li>따라서, 이 구간의 시청자 누적 재생시간은&nbsp;<code>10시간 00분 00초</code>&nbsp;+&nbsp;<code>20시간 00분 00초</code>&nbsp;+&nbsp;<code>05시간 00분 00초</code>&nbsp;=&nbsp;<code>35시간 00분 00초</code>&nbsp;입니다.</li>



<li>초록색으로 표시된 구간(<code>69:59:59-94:59:59</code>)에 광고를 삽입해도 동일한 결과를 얻을 수 있으나,&nbsp;<code>01:00:00</code>이&nbsp;<code>69:59:59</code>&nbsp;보다 빠른 시각이므로,&nbsp;<code>"01:00:00"</code>을 return 합니다.</li>
</ul>



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



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



<figure class="wp-block-image size-full"><img decoding="async" width="1096" height="323" src="https://lycos7560.com/wp-content/uploads/2023/05/image-82.png" alt="" class="wp-image-34782" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-82.png 1096w, https://lycos7560.com/wp-content/uploads/2023/05/image-82-300x88.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-82-768x226.png 768w" sizes="(max-width: 1096px) 100vw, 1096px" /></figure>



<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">삽입할 수 있는 위치는 맨 처음(<code>00:00:00</code>)이 유일합니다.</p>



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



<p><code>동영상 재생시간 = 재생이 종료된 시각 - 재생이 시작된 시각</code></p>



<p>(예를 들어, <code>00시 00분 01초</code>부터 <code>00시 00분 10초</code>까지 동영상이 재생되었다면, 동영상 재생시간은 <code>9초</code> 입니다.) </p>



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



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



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230514_223043316.jpg" alt="" class="wp-image-34788" width="1076" height="1440" srcset="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230514_223043316.jpg 1434w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230514_223043316-224x300.jpg 224w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230514_223043316-768x1028.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230514_223043316-1147x1536.jpg 1147w" sizes="(max-width: 1076px) 100vw, 1076px" /></figure>



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



<h2 class="wp-block-heading"><strong>주의</strong></h2>



<p class="has-medium-font-size">logs는 크기가 1 이상 300,000 이하인 문자열 배열</p>



<p class="has-medium-font-size">동영상 시간의 최대 범위는 360,000초</p>



<p class="has-medium-font-size">300,000 * 360,000 = 108,000,000,000</p>



<p class="has-medium-font-size">int의 범위 <strong>-2,147,483,648 ~ 2,147,483,647</strong>를 벗어난다.</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;string>
#include &lt;vector>
#include &lt;sstream>
#include &lt;cstdlib>
#include &lt;string>

using namespace std;

int Total_PT_Int, Total_ADV_Time, TimeLine[360000];
long long int _Res;

vector&lt;pair&lt;int, int>> Logs_Times;

int StringTimeConverter(string time) {
    int second;

    int to_hour = ((time[0] - '0') * 10) + (time[1] - '0');
    int to_min = ((time[3] - '0') * 10) + (time[4] - '0');
    int to_sec = ((time[6] - '0') * 10) + (time[7] - '0');
    second = to_hour * 3600 + to_min * 60 + to_sec;

    return second;
}

string IntToTimeString(int timeInSeconds) {
    int hours = timeInSeconds / 3600;
    int minutes = (timeInSeconds % 3600) / 60;
    int seconds = (timeInSeconds % 3600) % 60;
    string str;
    if (hours &lt; 10) str += "0" + to_string(hours) + ":";
    else str += to_string(hours) + ":";
    if (minutes &lt; 10) str += "0" + to_string(minutes) + ":";
    else str += to_string(minutes) + ":";
    if (seconds &lt; 10) str += "0" + to_string(seconds);
    else str += to_string(seconds);
    return str;
}

string solution(string play_time, string adv_time, vector&lt;string> logs) {
    string answer = "";
    Total_PT_Int = StringTimeConverter(play_time);
    Total_ADV_Time = StringTimeConverter(adv_time);
    for (auto&amp; it : logs)
    {
        vector&lt;string> _ResV;
        istringstream ss(it);
        string _temp;
        while (getline(ss, _temp, '-'))
            _ResV.push_back(_temp);
        int _Start = StringTimeConverter(_ResV[0]);
        int _End = StringTimeConverter(_ResV[1]); 
        Logs_Times.push_back(make_pair(_Start, _End));
        TimeLine[_Start]++;
        TimeLine[_End]--;
    }

    for (int i = 1; i &lt; Total_PT_Int; i++) 
        TimeLine[i] += TimeLine[i - 1];

    // 0 부터 시작
    int STime = 0;
    for (int i = 1; i &lt; Total_ADV_Time; i++)
        _Res += TimeLine[i - 1];
    long long int Max = _Res;


    for (int i = Total_ADV_Time; i &lt; Total_PT_Int; i++) {
        _Res += TimeLine[i];
        _Res -= TimeLine[i - Total_ADV_Time];
        if (_Res > Max) {
            Max = _Res;
           STime = i - Total_ADV_Time + 1;
        }
    }
    return IntToTimeString(STime);
}</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/05/image-83.png" alt="" class="wp-image-34784" width="475" height="974" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-83.png 358w, https://lycos7560.com/wp-content/uploads/2023/05/image-83-146x300.png 146w" sizes="(max-width: 475px) 100vw, 475px" /></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-72414-%ea%b4%91%ea%b3%a0-%ec%82%bd%ec%9e%85-2021-kakao-blind-recruitment/34776/">Programmers 72414 광고 삽입 [2021 KAKAO BLIND RECRUITMENT]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/programmers/programmers-72414-%ea%b4%91%ea%b3%a0-%ec%82%bd%ec%9e%85-2021-kakao-blind-recruitment/34776/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>백준 13549번 (숨바꼭질 3, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-13549%eb%b2%88-%ec%88%a8%eb%b0%94%ea%bc%ad%ec%a7%88-3-c-baekjoon/34748/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-13549%eb%b2%88-%ec%88%a8%eb%b0%94%ea%bc%ad%ec%a7%88-3-c-baekjoon/34748/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 12 May 2023 03:58:18 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[13549]]></category>
		<category><![CDATA[13549번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[deque]]></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[백준 13549]]></category>
		<category><![CDATA[백준 13549번]]></category>
		<category><![CDATA[숨바꼭질 3]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34748</guid>

					<description><![CDATA[<p>백준 13549번 '숨바꼭질 3' 문제에 대한 글입니다. deque을 이용한 BFS 탐색으로 해결하였습니다. (This article is about the question of "Hide and Seek 3" in Baekjoon Number 13549. It was solved by BFS search using deque.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-13549%eb%b2%88-%ec%88%a8%eb%b0%94%ea%bc%ad%ec%a7%88-3-c-baekjoon/34748/">백준 13549번 (숨바꼭질 3, 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-d4c04ba9      "
					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="#숨바꼭질-3" class="uagb-toc-link__trigger">숨바꼭질 3</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">숨바꼭질 3</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/13549" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/13549</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">72576</td><td class="has-text-align-left" data-align="left">20701</td><td class="has-text-align-left" data-align="left">13375</td><td class="has-text-align-left" data-align="left">24.997%</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">수빈이는 동생과&nbsp;숨바꼭질을 하고 있다. </p>



<p class="has-medium-font-size">수빈이는 현재 점 N(0 ≤ N ≤ 100,000)에 있고, 동생은 점 K(0 ≤ K ≤ 100,000)에&nbsp;있다.&nbsp;</p>



<p class="has-medium-font-size">수빈이는 걷거나 순간이동을 할 수 있다. </p>



<p class="has-medium-font-size">만약, 수빈이의 위치가 X일 때 걷는다면 1초 후에 X-1 또는 X+1로 이동하게 된다. </p>



<p class="has-medium-font-size">순간이동을 하는 경우에는 0초 후에 2*X의 위치로 이동하게 된다.</p>



<p class="has-medium-font-size">수빈이와 동생의 위치가 주어졌을 때, </p>



<p class="has-medium-font-size">수빈이가 동생을 찾을 수 있는 가장 빠른 시간이 몇 초 후인지 구하는 프로그램을 작성하시오.</p>



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



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



<p class="has-medium-font-size">첫 번째 줄에 수빈이가 있는 위치 N과 동생이 있는 위치 K가 주어진다.&nbsp;</p>



<p class="has-medium-font-size">N과 K는 정수이다.</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="">5 17</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="">2</pre>



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



<h2 class="wp-block-heading">힌트</h2>



<p class="has-medium-font-size">수빈이가 5-10-9-18-17 순으로 가면 2초만에 동생을 찾을 수 있다.</p>



<div style="height:40px" 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/board/search/all/problem/13549" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/board/search/all/problem/13549</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="">1 2</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="">0</pre>



<div style="height:50px" 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="">1 17</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="">1</pre>



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



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



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



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



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



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



<div style="height:50px" 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="">0 100000</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="">6</pre>



<div style="height:50px" 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/eric00513" target="_blank" rel="noreferrer noopener">eric00513</a>,&nbsp;<a href="https://www.acmicpc.net/user/idiot" target="_blank" rel="noreferrer noopener">idiot</a>,&nbsp;<a href="https://www.acmicpc.net/user/mohana9" target="_blank" rel="noreferrer noopener">mohana9</a>,&nbsp;<a href="https://www.acmicpc.net/user/tagun11" target="_blank" rel="noreferrer noopener">tagun11</a></li>
</ul>



<div style="height:50px" 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/1697" target="_blank" rel="noreferrer noopener">1697번. 숨바꼭질</a></li>



<li><a href="https://www.acmicpc.net/problem/12851" target="_blank" rel="noreferrer noopener">12851번. 숨바꼭질 2</a></li>



<li><a href="https://www.acmicpc.net/problem/13913" target="_blank" rel="noreferrer noopener">13913번. 숨바꼭질 4</a></li>
</ul>



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



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



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



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



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



<li><a href="https://www.acmicpc.net/problem/tag/22" target="_blank" rel="noreferrer noopener">데이크스트라</a></li>



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



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



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



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



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



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



<p class="has-medium-font-size">Deque을 이용한 탐색과 순서에 주의 (순간 이동은 시간이 증가하지 않는다.)</p>



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



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

using namespace std;

deque&lt;pair&lt;int, int>> _MyDeque;
int _N, _K, _Res;
bool _isVisted[100001];

int main()
{
	cin >> _N >> _K;
	_isVisted[_N] = true;
	_MyDeque.push_back(make_pair(_N, 0));
	while (!_MyDeque.empty()) {
		pair&lt;int, int> _Temp = _MyDeque.front();
		_MyDeque.pop_front();
		int _TempPos, _CntPos = _Temp.first;
		int _CntTime = _Temp.second;
		_isVisted[_Temp.first] = true;
		if (_Temp.first == _K) {
			_Res = _Temp.second;
			break;
		}

		_TempPos = _CntPos * 2;
		if (_TempPos &lt;= 100000 &amp;&amp; !_isVisted[_TempPos]) {
			_MyDeque.push_front(make_pair(_TempPos, _CntTime));
		}

		_TempPos = _CntPos + 1;
		if (_TempPos &lt;= 100000 &amp;&amp; !_isVisted[_TempPos]) {
			_MyDeque.push_back(make_pair(_TempPos, _CntTime + 1));
		}

		_TempPos = _CntPos - 1;
		if (_TempPos >= 0 &amp;&amp; !_isVisted[_TempPos]) {
			_MyDeque.push_back(make_pair(_TempPos, _CntTime + 1));
		}
	}

	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 is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/05/image-76.png" alt="" class="wp-image-34756" width="899" height="164" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-76.png 829w, https://lycos7560.com/wp-content/uploads/2023/05/image-76-300x55.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-76-768x140.png 768w" sizes="(max-width: 899px) 100vw, 899px" /></figure>



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



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-13549%eb%b2%88-%ec%88%a8%eb%b0%94%ea%bc%ad%ec%a7%88-3-c-baekjoon/34748/">백준 13549번 (숨바꼭질 3, 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-13549%eb%b2%88-%ec%88%a8%eb%b0%94%ea%bc%ad%ec%a7%88-3-c-baekjoon/34748/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
