<?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>brute force Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/brute-force/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Wed, 15 Oct 2025 05:34:59 +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>brute force Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>백준 1034번 (램프, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1034%eb%b2%88-%eb%9e%a8%ed%94%84-c-baekjoon/36454/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1034%eb%b2%88-%eb%9e%a8%ed%94%84-c-baekjoon/36454/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 11 Aug 2023 22:06:53 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1034]]></category>
		<category><![CDATA[1034번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Gold]]></category>
		<category><![CDATA[Gold4]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[골드]]></category>
		<category><![CDATA[골드4]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[램프]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1034]]></category>
		<category><![CDATA[백준 1034번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36454</guid>

					<description><![CDATA[<p>백준 1034번 '램프' 문제에 대한 글입니다. (This article is about the problem of 'Lamp' in Baekjoon Number 1034)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1034%eb%b2%88-%eb%9e%a8%ed%94%84-c-baekjoon/36454/">백준 1034번 (램프, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-70f244c5      "
					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></ol>					</div>
									</div>
				</div>
			


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



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



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



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



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



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



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



<p>지민이는 각 칸마다 (1×1크기의 정사각형) 램프가 들어있는 직사각형 모양의 탁자를 샀다. </p>



<p>모든 램프는 켜져있거나 꺼져있다. </p>



<p>각 열의 아래에는 스위치가 하나씩 달려있는데, 이 스위치를 누를 때마다 그 열에 있는 램프의 상태가 바뀐다. </p>



<p>켜져있는 램프는 꺼지고, 꺼져있는 램프는 켜진다)</p>



<p>만약 어떤 행에 있는 램프가 모두 켜져있을 때, 그 행이 켜져있다고 말한다. </p>



<p>지민이는 스위치를 K번 누를 것이다. 서로다른 스위치 K개를 누르지 않아도 된다. </p>



<p>지민이는 스위치를 K번 눌러서 켜져있는 행을 최대로 하려고 한다.</p>



<p>지민이의 탁자에 있는 램프의 상태와 K가 주어졌을 때, </p>



<p>스위치를 K번 누른 후에 켜져있는 행의 최댓값을 구하는 프로그램을 작성하시오.</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과 M이 주어진다. N은 행의 개수이고, M은 열의 개수이다. </p>



<p>N과 M은 50보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에는 램프의 상태가 주어진다. </p>



<p>1이 켜져있는 상태이고, 0이 꺼져있는 상태이다. </p>



<p>마지막 줄에는 K가 주어진다. </p>



<p>K는 1,000보다 작거나 같은 자연수 또는 0이다.</p>



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



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



<p>첫째 줄에 문제의 정답을 출력한다.</p>



<div style="height:41px" 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 2
01
10
10
1</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</pre>



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



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



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



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



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



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



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



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



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



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



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">14 3
001
101
001
000
111
001
101
111
110
000
111
010
110
001
6</pre>



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



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



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



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



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



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



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



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



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



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



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



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



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



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/109" target="_blank" rel="noreferrer noopener">애드 혹</a></li>
</ul>



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



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



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



<p>재귀를 이용한 BruteForce 알고리즘을 사용하여 테이블의 램프를 제어하는 방법으로 접근했으나 시간 초과로 통과하지 못하였다.</p>



<p>정답은 행에 램프가 꺼져있는 개수를 이용하여 푸는 방법</p>



<p>모든 행에서 K번 안에 모두 1로 바꿀 수 있는 행을 찾고 K가 짝수 홀수 인지에 대하여 확인한다.</p>



<p>만약 가능하다면 똑같은 행이 몇 개인지 확인하여 최댓값을 구한다.</p>



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



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

int _N, _M, _K, _Res = 0;
string _Table[50];
map&lt;string, pair&lt;int, int>> CheckMap;

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 >> _Table[i];
	cin >> _K;

	for (int i = 0; i &lt; _N; i++) {
		int _cnt = 0;

		for (int j = 0; j &lt; _M; j++)
			if (_Table[i][j] == '0')
				_cnt++;
		if (_cnt > _K) continue;
		auto it = CheckMap.find(_Table[i]);
		if (it != CheckMap.end()) it->second.second++;
		else CheckMap.insert({ _Table[i], {_cnt, 1}});
	}

	for (auto&amp; it : CheckMap)
		if (it.second.first % 2 == _K % 2)
		   _Res = max(_Res, it.second.second);
		
	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 fetchpriority="high" decoding="async" width="1204" height="187" src="https://lycos7560.com/wp-content/uploads/2023/08/image-4.png" alt="" class="wp-image-36464" style="width:750px;height:116px" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-4.png 1204w, https://lycos7560.com/wp-content/uploads/2023/08/image-4-300x47.png 300w, https://lycos7560.com/wp-content/uploads/2023/08/image-4-768x119.png 768w" sizes="(max-width: 1204px) 100vw, 1204px" /></figure>



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



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



<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-format="autorelaxed"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="4386247858"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1034%eb%b2%88-%eb%9e%a8%ed%94%84-c-baekjoon/36454/">백준 1034번 (램프, 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-1034%eb%b2%88-%eb%9e%a8%ed%94%84-c-baekjoon/36454/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 12924번 (멋진 쌍, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-12924%eb%b2%88-%eb%a9%8b%ec%a7%84-%ec%8c%8d-c-baekjoon/36435/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-12924%eb%b2%88-%eb%a9%8b%ec%a7%84-%ec%8c%8d-c-baekjoon/36435/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 09 Aug 2023 04:47:07 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[12924]]></category>
		<category><![CDATA[12924번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></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[백준 12924]]></category>
		<category><![CDATA[백준 12924번]]></category>
		<category><![CDATA[브루트 포스]]></category>
		<category><![CDATA[수학]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36435</guid>

					<description><![CDATA[<p>백준 12924번 '멋진 쌍' 문제에 대한 글입니다. '브루트포스' 알고리즘을 이용하여 문제를 해결하였습니다. (This article is about Baekjoon Number 12924 "Cool Pair" problem. We solved the problem using the 'Brute Force' algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-12924%eb%b2%88-%eb%a9%8b%ec%a7%84-%ec%8c%8d-c-baekjoon/36435/">백준 12924번 (멋진 쌍, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-1efa480d      "
					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><a href="https://www.acmicpc.net/problem/12924">https://www.acmicpc.net/problem/12924</a></p>



<div style="height:50px" 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">238</td><td class="has-text-align-left" data-align="left">88</td><td class="has-text-align-left" data-align="left">76</td><td class="has-text-align-left" data-align="left">38.191%</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, m)이 멋진 쌍일 조건은 다음과 같다.</p>



<ul class="wp-block-list">
<li>n의 뒤에서 몇 자리를 떼서, 앞에 그대로 붙이면 m을 얻을 수 있다.</li>
</ul>



<p>예를 들어, 12345의 뒤에서 345를 떼서 앞에 붙이면 34512가 되므로, (12345, 34512)는 멋진 쌍이다.</p>



<p>같은 개수의 자릿수를 갖는 두 자연수 A와 B가 주어질 때, A ≤ x &lt;&nbsp;y ≤ B 인 멋진 쌍 (x, y)의 개수를 출력하세요.</p>



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



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



<p>첫 번째 줄에 두 자연수 A, B가 주어진다. A ≤ B ≤ 2,000,000, A와 B의 자릿수 개수는 같다.</p>



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



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



<p>멋진 쌍의 개수를 자연수 하나로 출력한다.</p>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1 9</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="">0</pre>



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



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



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



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



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



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



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



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



<li><a href="https://www.acmicpc.net/problem/tag/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</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)"/>



<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;iostream>
#include &lt;string>
#include &lt;cmath>
#include &lt;set>
using namespace std;
set&lt;pair&lt;int, int>> _ResSet;
int _A, _B, _Res;
int FindingDigit(int _number)
{
	int dig = 0;
	while (_number) {
		_number /= 10;
		dig++;
	}
	return dig;
}

int main()
{
	cin >> _A >> _B;
	for (int i = _A; i &lt;= _B; i++) {
		int dig = FindingDigit(i);
		_ResSet.clear();
		for (int j = 1; j &lt;= dig - 1; j++) {
			int number = i;
			int _t = pow(10, j);
			int remainder = number % _t;
			int frontpart = number / _t;
			int frontpartDig = FindingDigit(frontpart);
			_t = pow(10, frontpartDig);
			int res = frontpart + (remainder * _t);
			if (dig != FindingDigit(res))
				continue;
			if (res > _B || res &lt; _A || res &lt;= number)
				continue;
			_ResSet.insert({ number, res });
		}
		_Res += _ResSet.size();
	}
	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="1207" height="99" src="https://lycos7560.com/wp-content/uploads/2023/08/image-3.png" alt="" class="wp-image-36447" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-3.png 1207w, https://lycos7560.com/wp-content/uploads/2023/08/image-3-300x25.png 300w, https://lycos7560.com/wp-content/uploads/2023/08/image-3-768x63.png 768w" sizes="(max-width: 1207px) 100vw, 1207px" /></figure>



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



<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-format="autorelaxed"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="4386247858"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-12924%eb%b2%88-%eb%a9%8b%ec%a7%84-%ec%8c%8d-c-baekjoon/36435/">백준 12924번 (멋진 쌍, 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-12924%eb%b2%88-%eb%a9%8b%ec%a7%84-%ec%8c%8d-c-baekjoon/36435/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 20529번 (가장 가까운 세 사람의 심리적 거리, C++) [BAEKJOON]</title>
		<link>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/</link>
					<comments>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/#comments</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 14 Jul 2023 22:16:16 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[20529]]></category>
		<category><![CDATA[20529번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[bit]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[MBTI]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[가장 가까운 세 사람의 심리적 거리]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 20529]]></category>
		<category><![CDATA[백준 20529번]]></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=36060</guid>

					<description><![CDATA[<p>가장 가까운 세 사람의 심리적 거리 https://www.acmicpc.net/problem/20529 시간 제한 메모리 제한 제출 정답 맞힌 사람 정답 비율 2 초 1536 MB 4043 1550 1185 36.744% 문제 여러분은 요즘 유행하는 심리검사인 MBTI에 대해 들어보았는가? MBTI(Myers-Briggs Type Indicator)는&#160;C.G.Jung의 심리유형론을 근거로 하여 Katharine Cook Briggs와 Isabel Briggs Myers가 보다 쉽고 일상생활에 유용하게 활용할 수 있도록 고안한 자기보고식 성격유형지표이다. [&#8230;]</p>
<p>The post <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> 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-b726977e      "
					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><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:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">가장 가까운 세 사람의 심리적 거리</h1>



<p><a href="https://www.acmicpc.net/problem/20529" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/20529</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">1536 MB</td><td class="has-text-align-left" data-align="left">4043</td><td class="has-text-align-left" data-align="left">1550</td><td class="has-text-align-left" data-align="left">1185</td><td class="has-text-align-left" data-align="left">36.744%</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>여러분은 요즘 유행하는 심리검사인 MBTI에 대해 들어보았는가?</p>



<p>MBTI(Myers-Briggs Type Indicator)는&nbsp;C.G.Jung의 심리유형론을 근거로 하여 Katharine Cook Briggs와 Isabel Briggs Myers가 보다 쉽고 </p>



<p>일상생활에 유용하게 활용할 수 있도록 고안한 자기보고식 성격유형지표이다. (출처: 위키백과)</p>



<p>MBTI는 아래와 같이 네 가지 척도로 사람들의 성격을 구분한다.</p>



<ul class="wp-block-list">
<li>외향(E) / 내향(I)</li>



<li>감각(S) / 직관(N)</li>



<li>사고(T) / 감정(F)</li>



<li>판단(J) / 인식(P)</li>
</ul>



<p>각 척도마다 두 가지 분류가 존재하므로, MBTI는 총&nbsp;2^4 = 16가지 유형이 있음을 알 수 있다. </p>



<p>일반적으로&nbsp;MBTI의 유형들은 각 분류를 나타내는 알파벳 한 글자씩을 따 네 글자로 표시하게 된다. </p>



<p>모든 유형의 목록은 다음과 같다.</p>



<ul class="wp-block-list">
<li>ISTJ, ISFJ, INFJ, INTJ, ISTP, ISFP, INFP, INTP, ESTP, ESFP, ENFP, ENTP, ESTJ, ESFJ, ENFJ, ENTJ</li>
</ul>



<p>MBTI 성격 유형을 이용하면&nbsp;두 사람 사이의 심리적인 거리를 정의할 수 있다. </p>



<p>이는&nbsp;두 사람의 MBTI 유형에서&nbsp;서로 다른 분류에 속하는 척도의 수로 정의된다. </p>



<p>예를 들어, MBTI 유형이 ISTJ인 사람과 ISFJ인 사람 사이의 거리는 1이며, INTP인 사람과 ENTJ인 사람 사이의 거리는 2이다.</p>



<p>이 정의를 확장해서 세&nbsp;사람 사이의 심리적인 거리도 정의할 수 있다.&nbsp;</p>



<p>세 사람&nbsp;A, B, C가 있을 때 이들의 심리적인 거리는</p>



<p>(A와&nbsp;B&nbsp;사이의 심리적인&nbsp;거리)&nbsp;+ (B와&nbsp;C&nbsp;사이의 심리적인&nbsp;거리)&nbsp;+ (A와&nbsp;C&nbsp;사이의 심리적인&nbsp;거리)로 정의한다.</p>



<p>대학교에서 심리학 교수로&nbsp;일하는 종서는 자신이 가르치는 학생들의 심리적인 특성을 분석하고 싶어한다.</p>



<p>오늘이 생일인 종서를 위해&nbsp;N명의 학생들의 MBTI 유형이 주어질 때, </p>



<p>가장 가까운 세&nbsp;학생 사이의 심리적인 거리를 구해보자.</p>



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



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



<p>첫 줄에는 테스트 케이스의 수를 나타내는 정수&nbsp;T가 주어진다.</p>



<p>각 테스트 케이스의 첫 줄에는 학생의 수를 나타내는 하나의 정수&nbsp;N이 주어지며, </p>



<p>두 번째 줄에는 각 학생의 MBTI 성격 유형을 나타내는 문자열들이 사이에 공백을 두고 주어진다.</p>



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



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



<p>각 테스트 케이스에 대한 답을 정수 형태로 한 줄에 하나씩 출력한다.</p>



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



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



<ul class="wp-block-list">
<li> 1≤ T ≤50 </li>



<li> 3≤ N ≤100000</li>



<li>각 테스트 케이스의 N의 합은 100,000을 넘지 않는다.</li>
</ul>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">3
3
ENTJ INTP ESFJ
4
ESFP ESFP ESFP ESFP
5
INFP INFP ESTP ESTJ ISTJ</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="">8
0
4</pre>



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



<ul class="wp-block-list">
<li>첫 번째 테스트 케이스의 경우, ENTJ와 INTP의 심리적인 거리는 2, <br>ENTJ와 ESFJ의 심리적인 거리는 2, INTP와 ESFJ의 심리적인 거리는 4이므로 세 사람의 심리적인 거리는 2+2+4=8이다.</li>



<li>두 번째 테스트 케이스의 경우, 어떤 사람 둘을 골라도 심리적인 거리가 0이므로 가장 가까운 세 사람의 심리적인 거리는 0이다.</li>



<li>세 번째 테스트 케이스의 경우, 심리적인 거리를 최소화하려면 MBTI가 ESTP, ESTJ, ISTJ인 세 사람을 골라야 한다. <br>ESTP와 ESTJ의 심리적인 거리는 1, ESTP와 ISTJ의 심리적인 거리는 2, ESTJ와 ISTJ의 심리적인 거리는 1이므로 세 사람의 심리적인 거리는 1+2+1=4이다.</li>
</ul>



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



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



<p><a href="https://www.acmicpc.net/category/45" target="_blank" rel="noreferrer noopener">Contest</a> > <a href="https://www.acmicpc.net/category/469" target="_blank" rel="noreferrer noopener">Good Bye, BOJ</a> > <a href="https://www.acmicpc.net/category/detail/2379" target="_blank" rel="noreferrer noopener">Good Bye, BOJ 2020!</a> B번</p>



<ul class="wp-block-list">
<li>문제를 검수한 사람: <a href="https://www.acmicpc.net/user/ahgus89" target="_blank" rel="noreferrer noopener">ahgus89</a>, <a href="https://www.acmicpc.net/user/cgiosy" target="_blank" rel="noreferrer noopener">cgiosy</a>, <a href="https://www.acmicpc.net/user/cheetose" target="_blank" rel="noreferrer noopener">cheetose</a>, <a href="https://www.acmicpc.net/user/cs71107" target="_blank" rel="noreferrer noopener">cs71107</a>, <a href="https://www.acmicpc.net/user/evenharder" target="_blank" rel="noreferrer noopener">evenharder</a>, <a href="https://www.acmicpc.net/user/gravekper" target="_blank" rel="noreferrer noopener">gravekper</a>, <a href="https://www.acmicpc.net/user/jhnah917" target="_blank" rel="noreferrer noopener">jhnah917</a>, <a href="https://www.acmicpc.net/user/junseo" target="_blank" rel="noreferrer noopener">junseo</a>, <a href="https://www.acmicpc.net/user/kdh9949" target="_blank" rel="noreferrer noopener">kdh9949</a>, <a href="https://www.acmicpc.net/user/koosaga">koosaga</a>, <a href="https://www.acmicpc.net/user/queued_q" target="_blank" rel="noreferrer noopener">queued_q</a>, <a href="https://www.acmicpc.net/user/rdd6584" target="_blank" rel="noreferrer noopener">rdd6584</a>, <a href="https://www.acmicpc.net/user/ryute" target="_blank" rel="noreferrer noopener">ryute</a></li>



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



<li>문제를 만든 사람: <a href="https://www.acmicpc.net/user/leejseo" target="_blank" rel="noreferrer noopener">leejseo</a>, <a href="https://www.acmicpc.net/user/queued_q" target="_blank" rel="noreferrer noopener">queued_q</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><a href="https://www.acmicpc.net/problem/tag/124">학</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/189" target="_blank" rel="noreferrer noopener">비둘기집 원리</a></li>
</ul>



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



<figure class="wp-block-embed is-type-wp-embed is-provider-어제와-내일의-나-그-사이의-이야기 wp-block-embed-어제와-내일의-나-그-사이의-이야기"><div class="wp-block-embed__wrapper">
<blockquote class="wp-embedded-content" data-secret="8eWN1jIoBu"><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></blockquote><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  title="&#8220;알고리즘 – 비둘기 집의 원리 (Pigeonhole Principle)&#8221; &#8212; 어제와 내일의 나 그 사이의 이야기" src="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/embed/#?secret=t2KQIZOfcp#?secret=8eWN1jIoBu" data-secret="8eWN1jIoBu" 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>



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



<p>비둘기 집의 원리를 이용하여 N &gt; 32 인 경우를 처리해주는 것이 문제의 포인트</p>



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



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;vector>
using namespace std;
int _T, _N, _Res = INT32_MAX;
string _Str;
int main()
{
	ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	cin >> _T;
	for (int i = 0; i &lt; _T; i++) {
		cin >> _N;
		vector&lt;string> _StrV;
		for (int i = 0; i &lt; _N; i++) {
			cin >> _Str;
			_StrV.push_back(_Str);
		}
		if (_N > 32) {
			std::cout &lt;&lt; 0 &lt;&lt; "\n";
			continue;
		}
		int _Sum;
		_Res = INT32_MAX;
		for (int i = 0; i &lt; _N; i++) {
			for (int j = i + 1; j &lt; _N; j++) {
				for (int k = j + 1; k &lt; _N; k++) {
					_Sum = 0;
					for (int q = 0; q &lt; 4; q++) {
						if (_StrV[i][q] != _StrV[j][q]) _Sum++;
						if (_StrV[j][q] != _StrV[k][q]) _Sum++;
						if (_StrV[k][q] != _StrV[i][q]) _Sum++;
					}
					_Res = min(_Res, _Sum);
				}
			}
		}
		std::cout &lt;&lt; _Res &lt;&lt; "\n";
	}

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1061" height="88" src="https://lycos7560.com/wp-content/uploads/2023/07/image-33.png" alt="" class="wp-image-36070" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-33.png 1061w, https://lycos7560.com/wp-content/uploads/2023/07/image-33-300x25.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-33-768x64.png 768w" sizes="(max-width: 1061px) 100vw, 1061px" /></figure>



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



<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;iostream>
#include &lt;vector>
using namespace std;
int _T, _N, _Res = INT32_MAX;
vector&lt;int> _bitV;
string _Str;
int main()
{
	ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	cin >> _T;
	for (int i = 0; i &lt; _T; i++) {
		cin >> _N;
		_bitV.clear();
		for (int i = 0; i &lt; _N; i++) {
			cin >> _Str;
			int _bit = 0;
			if (_Str[0] == 'I') _bit += 1 &lt;&lt; 0;
			if (_Str[1] == 'N') _bit += 1 &lt;&lt; 1;
			if (_Str[2] == 'F') _bit += 1 &lt;&lt; 2;
			if (_Str[3] == 'P') _bit += 1 &lt;&lt; 3;
			_bitV.push_back(_bit);
		}
		if (_N > 32) {
			std::cout &lt;&lt; 0 &lt;&lt; "\n";
			continue;
		}
		int _Sum;
		_Res = INT32_MAX;
		for (int i = 0; i &lt; _N; i++) {
			for (int j = i + 1; j &lt; _N; j++) {
				for (int k = j + 1; k &lt; _N; k++) {
					_Sum = 0;
					for (int q = 0; q &lt; 4; q++) {
						if ((_bitV[i] &amp; (1 &lt;&lt; q)) != (_bitV[j] &amp; (1 &lt;&lt; q))) _Sum++;
						if ((_bitV[j] &amp; (1 &lt;&lt; q)) != (_bitV[k] &amp; (1 &lt;&lt; q))) _Sum++;
						if ((_bitV[k] &amp; (1 &lt;&lt; q)) != (_bitV[i] &amp; (1 &lt;&lt; q))) _Sum++;
					}
					_Res = min(_Res, _Sum);
				}
			}
		}
		std::cout &lt;&lt; _Res &lt;&lt; "\n";
	}

	return 0;
}</pre>



<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-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> 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-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/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Programmers 60063 블록 이동하기 [2020 KAKAO BLIND RECRUITMENT]</title>
		<link>https://lycos7560.com/cpp/programmers/programmers-60063-%eb%b8%94%eb%a1%9d-%ec%9d%b4%eb%8f%99%ed%95%98%ea%b8%b0-2020-kakao-blind-recruitment/34310/</link>
					<comments>https://lycos7560.com/cpp/programmers/programmers-60063-%eb%b8%94%eb%a1%9d-%ec%9d%b4%eb%8f%99%ed%95%98%ea%b8%b0-2020-kakao-blind-recruitment/34310/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 14 Apr 2023 12:20:12 +0000</pubDate>
				<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[[2020 KAKAO BLIND RECRUITMENT]]]></category>
		<category><![CDATA[2020 KAKAO BLIND RECRUITMENT]]></category>
		<category><![CDATA[60063]]></category>
		<category><![CDATA[60063번]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Programmers 60063]]></category>
		<category><![CDATA[Programmers 60063번]]></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=34310</guid>

					<description><![CDATA[<p>Programmers 60063번 '블록 이동하기' 문제에 대한 글입니다. BFS 탐색 및 브루트포스 알고리즘을 이용하여 해결하였습니다. This article is about Programmers 60063 'Move Block' It was solved using the BFS search and Bruteforce algorithm. [2020 KAKAO BLIND RECRUITMENT]</p>
<p>The post <a href="https://lycos7560.com/cpp/programmers/programmers-60063-%eb%b8%94%eb%a1%9d-%ec%9d%b4%eb%8f%99%ed%95%98%ea%b8%b0-2020-kakao-blind-recruitment/34310/">Programmers 60063 블록 이동하기 [2020 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-52368673      "
					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><a href="https://school.programmers.co.kr/learn/courses/30/lessons/60063" target="_blank" rel="noreferrer noopener">https://school.programmers.co.kr/lear</a><a href="https://school.programmers.co.kr/learn/courses/30/lessons/60063">n/courses/30/lessons/60063</a></p>



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



<p class="has-medium-font-size">로봇개발자&nbsp;<strong>&#8220;무지&#8221;</strong>는 한 달 앞으로 다가온 &#8220;카카오배 로봇경진대회&#8221;에 출품할&nbsp;<strong>로봇</strong>을 준비하고 있습니다. </p>



<p class="has-medium-font-size">준비 중인 로봇은&nbsp;<strong><code>2 x 1</code></strong>&nbsp;크기의 로봇으로 &#8220;무지&#8221;는&nbsp;<strong>&#8220;0&#8221;</strong>과&nbsp;<strong>&#8220;1&#8221;</strong>로 이루어진&nbsp;<strong><code>N x N</code></strong>&nbsp;크기의 지도에서&nbsp;<strong><code>2 x 1</code></strong>&nbsp;크기인 로봇을 움직여&nbsp;</p>



<p class="has-medium-font-size"><strong>(N, N)</strong>&nbsp;위치까지 이동 할 수 있도록 프로그래밍을 하려고 합니다. 로봇이 이동하는 지도는 가장 왼쪽, 상단의 좌표를&nbsp;<strong>(1, 1)</strong>로 하며 </p>



<p class="has-medium-font-size">지도 내에 표시된 숫자&nbsp;<strong>&#8220;0&#8221;</strong>은 빈칸을&nbsp;<strong>&#8220;1&#8221;</strong>은 벽을 나타냅니다. 로봇은 벽이 있는 칸 또는 지도 밖으로는 이동할 수 없습니다. </p>



<p class="has-medium-font-size">로봇은 처음에 아래 그림과 같이 좌표&nbsp;<strong>(1, 1)</strong>&nbsp;위치에서 가로방향으로 놓여있는 상태로 시작하며, 앞뒤 구분없이 움직일 수 있습니다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="783" height="787" src="https://lycos7560.com/wp-content/uploads/2023/04/image-10.png" alt="" class="wp-image-34312" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-10.png 783w, https://lycos7560.com/wp-content/uploads/2023/04/image-10-298x300.png 298w, https://lycos7560.com/wp-content/uploads/2023/04/image-10-150x150.png 150w, https://lycos7560.com/wp-content/uploads/2023/04/image-10-768x772.png 768w" sizes="(max-width: 783px) 100vw, 783px" /></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">예를 들어, 위 그림에서 오른쪽으로 한 칸 이동한다면&nbsp;<strong>(1, 2), (1, 3)</strong>&nbsp;두 칸을 차지하게 되며, </p>



<p class="has-medium-font-size">아래로 이동한다면&nbsp;<strong>(2, 1), (2, 2)</strong>&nbsp;두 칸을 차지하게 됩니다. </p>



<p class="has-medium-font-size">로봇이 차지하는 두 칸 중 어느 한 칸이라도&nbsp;<strong>(N, N)</strong>&nbsp;위치에 도착하면 됩니다.</p>



<p class="has-medium-font-size">로봇은 다음과 같이 조건에 따라 회전이 가능합니다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="788" height="789" src="https://lycos7560.com/wp-content/uploads/2023/04/image-11.jpg" alt="" class="wp-image-34313" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-11.jpg 788w, https://lycos7560.com/wp-content/uploads/2023/04/image-11-300x300.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/04/image-11-150x150.jpg 150w, https://lycos7560.com/wp-content/uploads/2023/04/image-11-768x769.jpg 768w" sizes="(max-width: 788px) 100vw, 788px" /></figure>



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



<p class="has-medium-font-size">위 그림과 같이 로봇은 90도씩 회전할 수 있습니다. </p>



<p class="has-medium-font-size">단, 로봇이 차지하는 두 칸 중, 어느 칸이든 축이 될 수 있지만, </p>



<p class="has-medium-font-size">회전하는 방향(축이 되는 칸으로부터 대각선 방향에 있는 칸)에는 벽이 없어야 합니다. </p>



<p class="has-medium-font-size">로봇이 한 칸 이동하거나 90도 회전하는 데는 걸리는 시간은 정확히 1초 입니다.</p>



<p class="has-medium-font-size"><strong>&#8220;0&#8221;</strong>과&nbsp;<strong>&#8220;1&#8221;</strong>로 이루어진 지도인 board가 주어질 때, </p>



<p class="has-medium-font-size">로봇이&nbsp;<strong>(N, N)</strong>&nbsp;위치까지 이동하는데 필요한 최소 시간을 return 하도록 solution 함수를 완성해주세요.</p>



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



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



<p class="has-small-font-size">board의 한 변의 길이는 5 이상 100 이하입니다.</p>



<p class="has-small-font-size">board의 원소는 0 또는 1입니다.</p>



<p class="has-small-font-size">로봇이 처음에 놓여 있는 칸 (1, 1), (1, 2)는 항상 0으로 주어집니다.</p>



<p class="has-small-font-size">로봇이 항상 목적지에 도착할 수 있는 경우만 입력으로 주어집니다.</p>



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



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



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">board</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">[[0, 0, 0, 1, 1],[0, 0, 0, 1, 0],[0, 1, 0, 1, 1],[1, 1, 0, 0, 1],[0, 0, 0, 0, 0]]</td><td class="has-text-align-left" data-align="left">7</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">문제에 주어진 예시와 같습니다.</p>



<p class="has-medium-font-size">로봇이 오른쪽으로 한 칸 이동 후, (1, 3) 칸을 축으로 반시계 방향으로 90도 회전합니다. </p>



<p class="has-medium-font-size">다시, 아래쪽으로 3칸 이동하면 로봇은 (4, 3), (5, 3) 두 칸을 차지하게 됩니다. </p>



<p class="has-medium-font-size">이제 (5, 3)을 축으로 시계 방향으로 90도 회전 후, 오른쪽으로 한 칸 이동하면 (N, N)에 도착합니다. </p>



<p class="has-medium-font-size">따라서 목적지에 도달하기까지 최소 7초가 걸립니다.</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"><img decoding="async" width="1125" height="1280" src="https://lycos7560.com/wp-content/uploads/2023/04/Notes_230414_203835-2-2.jpg" alt="" class="wp-image-34336" srcset="https://lycos7560.com/wp-content/uploads/2023/04/Notes_230414_203835-2-2.jpg 1125w, https://lycos7560.com/wp-content/uploads/2023/04/Notes_230414_203835-2-2-264x300.jpg 264w, https://lycos7560.com/wp-content/uploads/2023/04/Notes_230414_203835-2-2-768x874.jpg 768w" sizes="(max-width: 1125px) 100vw, 1125px" /></figure>



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

using namespace std;

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

bool _MapArr[101][101][2];

// 로봇의 위치 및 현재 시간
tuple&lt;int, int, int, int, int> _RobotPos;
// bfs 탐색을 위한 q
queue&lt;tuple&lt;int, int, int, int, int>> _RobotPosQ;

int solution(vector&lt;vector&lt;int>> board) {
    int answer = 0;
    int _MapMax = board.size();
    pair&lt;int, int> _goal = make_pair(_MapMax - 1, _MapMax - 1); // 목표를 설정

    _RobotPos = make_tuple(0, 0, 0, 1, 0); // 로봇의 위치 초기값
    _RobotPosQ.push(_RobotPos); // 로봇의 시작를 큐에 넣기
    _MapArr[0][0][0] = true; // 방문 마킹
    _MapArr[0][1][0] = true;
    // board 는 0,0 에서 시작
    // 마킹은 1,1에서 시작


    // bfs 탐색 시작
    while (_RobotPosQ.size() > 0) {
        _RobotPos = _RobotPosQ.front();
        _RobotPosQ.pop();
        pair&lt;int, int> _CntPosOne = make_pair(get&lt;0>(_RobotPos), get&lt;1>(_RobotPos)); // 로봇의 현재 x, y 위치 1
        pair&lt;int, int> _CntPosTwo = make_pair(get&lt;2>(_RobotPos), get&lt;3>(_RobotPos)); // 로봇의 현재 x, y 위치 2
        int _cnttime = get&lt;4>(_RobotPos);
        if (_CntPosOne == _goal || _CntPosTwo == _goal) {
            answer = _cnttime;
            break;
        }
        bool _robotstatus; // true 세로, false 가로
        // 상 하 좌 우를 탐색
        for (int i = 0; i &lt; 4; i++) {

            pair&lt;int, int> _TempPosOne, _TempPosTwo;
            _TempPosOne.first = _CntPosOne.first + dxdy[i][0];
            _TempPosOne.second = _CntPosOne.second + dxdy[i][1];
            _TempPosTwo.first = _CntPosTwo.first + dxdy[i][0];
            _TempPosTwo.second = _CntPosTwo.second + dxdy[i][1];

            // 가로 세로 비교
            if (_CntPosOne.first + 1 == _CntPosTwo.first || _CntPosOne.first - 1 == _CntPosTwo.first) _robotstatus = true; // 세로
            else _robotstatus = false;

            // 벽이라면 넘어간다.
            if (_TempPosOne.first &lt; 0 || _TempPosOne.first >= _MapMax || _TempPosOne.second &lt; 0 || _TempPosOne.second >= _MapMax) continue;
            if (_TempPosTwo.first &lt; 0 || _TempPosTwo.first >= _MapMax || _TempPosTwo.second &lt; 0 || _TempPosTwo.second >= _MapMax) continue;
            if (board[_TempPosOne.first][_TempPosOne.second] == 1 || board[_TempPosTwo.first][_TempPosTwo.second] == 1) continue;

            // 두 부분이 방문한 적이 있다면 넘어간다.
            if (_MapArr[_TempPosOne.first][_TempPosOne.second][_robotstatus] == true &amp;&amp; _MapArr[_TempPosTwo.first][_TempPosTwo.second][_robotstatus] == true) continue;

            _RobotPos = make_tuple(_TempPosOne.first, _TempPosOne.second, _TempPosTwo.first, _TempPosTwo.second, _cnttime + 1);
            _RobotPosQ.push(_RobotPos); // 로봇의 시작를 큐에 넣기
            _MapArr[_TempPosOne.first][_TempPosOne.second][_robotstatus] = true; // 방문 마킹
            _MapArr[_TempPosTwo.first][_TempPosTwo.second][_robotstatus] = true;

        }

        // 방향 전환
        if (!_robotstatus) { // 가로
            if (_CntPosOne.first + 1 &lt; _MapMax &amp;&amp; board[_CntPosOne.first + 1][_CntPosOne.second] != 1 &amp;&amp; board[_CntPosTwo.first + 1][_CntPosTwo.second] != 1) {
                if (_MapArr[_CntPosTwo.first + 1][_CntPosTwo.second][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosTwo.first + 1, _CntPosTwo.second, _CntPosTwo.first, _CntPosTwo.second, _cnttime + 1);
                    _MapArr[_CntPosTwo.first + 1][_CntPosTwo.second][!_robotstatus] = true;
                    _MapArr[_CntPosTwo.first][_CntPosTwo.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }
            if (_CntPosOne.first - 1 >= 0 &amp;&amp; board[_CntPosOne.first - 1][_CntPosOne.second] != 1 &amp;&amp; board[_CntPosTwo.first - 1][_CntPosTwo.second] != 1) {
                if (_MapArr[_CntPosTwo.first - 1][_CntPosTwo.second][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosTwo.first - 1, _CntPosTwo.second, _CntPosTwo.first, _CntPosTwo.second, _cnttime + 1);
                    _MapArr[_CntPosTwo.first - 1][_CntPosTwo.second][!_robotstatus] = true;
                    _MapArr[_CntPosTwo.first][_CntPosTwo.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }
            if (_CntPosTwo.first + 1 &lt; _MapMax &amp;&amp; board[_CntPosTwo.first + 1][_CntPosTwo.second] != 1 &amp;&amp; board[_CntPosOne.first + 1][_CntPosOne.second] != 1) {
                if (_MapArr[_CntPosOne.first + 1][_CntPosOne.second][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosOne.first + 1, _CntPosOne.second, _CntPosOne.first, _CntPosOne.second, _cnttime + 1);
                    _MapArr[_CntPosOne.first + 1][_CntPosOne.second][!_robotstatus] = true;
                    _MapArr[_CntPosOne.first][_CntPosOne.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }
            if (_CntPosTwo.first - 1 >= 0 &amp;&amp; board[_CntPosTwo.first - 1][_CntPosTwo.second] != 1 &amp;&amp; board[_CntPosOne.first - 1][_CntPosOne.second] != 1) {
                if (_MapArr[_CntPosOne.first - 1][_CntPosOne.second][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosOne.first - 1, _CntPosOne.second, _CntPosOne.first, _CntPosOne.second, _cnttime + 1);
                    _MapArr[_CntPosOne.first - 1][_CntPosOne.second][!_robotstatus] = true;
                    _MapArr[_CntPosOne.first][_CntPosOne.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }
        }
        else {
            if (_CntPosOne.second + 1 &lt; _MapMax &amp;&amp; board[_CntPosOne.first][_CntPosOne.second + 1] != 1 &amp;&amp; board[_CntPosTwo.first][_CntPosTwo.second + 1] != 1) {
                if (_MapArr[_CntPosTwo.first][_CntPosTwo.second + 1][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosTwo.first, _CntPosTwo.second + 1, _CntPosTwo.first, _CntPosTwo.second, _cnttime + 1);
                    _MapArr[_CntPosTwo.first][_CntPosTwo.second + 1][!_robotstatus] = true;
                    _MapArr[_CntPosTwo.first][_CntPosTwo.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }
            if (_CntPosOne.second - 1 >= 0 &amp;&amp; board[_CntPosOne.first][_CntPosOne.second - 1] != 1 &amp;&amp; board[_CntPosTwo.first][_CntPosTwo.second - 1] != 1) {
                if (_MapArr[_CntPosTwo.first][_CntPosTwo.second - 1][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosTwo.first, _CntPosTwo.second - 1, _CntPosTwo.first, _CntPosTwo.second, _cnttime + 1);
                    _MapArr[_CntPosTwo.first][_CntPosTwo.second - 1][!_robotstatus] = true;
                    _MapArr[_CntPosTwo.first][_CntPosTwo.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }
            if (_CntPosTwo.second + 1 &lt; _MapMax &amp;&amp; board[_CntPosTwo.first][_CntPosTwo.second + 1] != 1 &amp;&amp; board[_CntPosOne.first][_CntPosOne.second + 1] != 1) {
                if (_MapArr[_CntPosOne.first][_CntPosOne.second + 1][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosOne.first, _CntPosOne.second + 1, _CntPosOne.first, _CntPosOne.second, _cnttime + 1);
                    _MapArr[_CntPosOne.first][_CntPosOne.second + 1][!_robotstatus] = true;
                    _MapArr[_CntPosOne.first][_CntPosOne.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }
            if (_CntPosTwo.second - 1 >= 0 &amp;&amp; board[_CntPosTwo.first][_CntPosTwo.second - 1] != 1 &amp;&amp; board[_CntPosOne.first][_CntPosOne.second - 1] != 1) {
                if (_MapArr[_CntPosOne.first][_CntPosOne.second - 1][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosOne.first, _CntPosOne.second - 1, _CntPosOne.first, _CntPosOne.second, _cnttime + 1);
                    _MapArr[_CntPosOne.first][_CntPosOne.second - 1][!_robotstatus] = true;
                    _MapArr[_CntPosOne.first][_CntPosOne.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }

        }

    }

    return answer;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="686" height="429" src="https://lycos7560.com/wp-content/uploads/2023/04/image-12.png" alt="" class="wp-image-34318" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-12.png 686w, https://lycos7560.com/wp-content/uploads/2023/04/image-12-300x188.png 300w" sizes="(max-width: 686px) 100vw, 686px" /></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/programmers/programmers-60063-%eb%b8%94%eb%a1%9d-%ec%9d%b4%eb%8f%99%ed%95%98%ea%b8%b0-2020-kakao-blind-recruitment/34310/">Programmers 60063 블록 이동하기 [2020 KAKAO BLIND RECRUITMENT]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/programmers/programmers-60063-%eb%b8%94%eb%a1%9d-%ec%9d%b4%eb%8f%99%ed%95%98%ea%b8%b0-2020-kakao-blind-recruitment/34310/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 14500번 (테트로미노, C++) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-14500%eb%b2%88-%ed%85%8c%ed%8a%b8%eb%a1%9c%eb%af%b8%eb%85%b8-c-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33194/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-14500%eb%b2%88-%ed%85%8c%ed%8a%b8%eb%a1%9c%eb%af%b8%eb%85%b8-c-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33194/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 16 Feb 2023 01:53:01 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[14500]]></category>
		<category><![CDATA[14500번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></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[백준 14500]]></category>
		<category><![CDATA[백준 14500번]]></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=33194</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 14500번 '테트로미노' 문제에 대한 글입니다. 'brute force' 알고리즘과 'DFS 탐색'을 이용하여 해결하였습니다. (This is BAEKJOON's 14500 article on the 'Tetromino' problem. It was solved using the 'brute force' algorithm and 'DFS search'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-14500%eb%b2%88-%ed%85%8c%ed%8a%b8%eb%a1%9c%eb%af%b8%eb%85%b8-c-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33194/">백준 14500번 (테트로미노, 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-6eabfa96      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#테트로미노" class="uagb-toc-link__trigger">테트로미노</a><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a><li class="uagb-toc__list"><a href="#추가-반례" class="uagb-toc-link__trigger">추가 반례</a></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">테트로미노</h1>



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



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



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">2 초</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">69583</td><td class="has-text-align-left" data-align="left">26178</td><td class="has-text-align-left" data-align="left">17011</td><td class="has-text-align-left" data-align="left">35.673%</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">폴리오미노란 크기가 1×1인 정사각형을 여러 개 이어서 붙인 도형이며, 다음과 같은 조건을 만족해야 한다.</p>



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



<p class="has-medium-font-size">정사각형은 서로 겹치면 안 된다.</p>



<p class="has-medium-font-size">도형은 모두 연결되어 있어야 한다.</p>



<p class="has-medium-font-size">정사각형의 변끼리 연결되어 있어야 한다. 즉, 꼭짓점과 꼭짓점만 맞닿아 있으면 안 된다.</p>



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



<p class="has-medium-font-size">정사각형 4개를 이어 붙인 폴리오미노는 테트로미노라고 하며, 다음과 같은 5가지가 있다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="488" height="308" src="https://lycos7560.com/wp-content/uploads/2023/02/image-73.png" alt="" class="wp-image-33195" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-73.png 488w, https://lycos7560.com/wp-content/uploads/2023/02/image-73-300x189.png 300w" sizes="(max-width: 488px) 100vw, 488px" /></figure>



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



<p class="has-medium-font-size">아름이는 크기가 N×M인 종이 위에 테트로미노 하나를 놓으려고 한다. </p>



<p class="has-medium-font-size">종이는 1×1 크기의 칸으로 나누어져 있으며, 각각의 칸에는 정수가 하나 쓰여 있다.</p>



<p class="has-medium-font-size">테트로미노 하나를 적절히 놓아서 테트로미노가 놓인 칸에 쓰여 있는 수들의 합을 최대로 하는 프로그램을 작성하시오.</p>



<p class="has-medium-font-size">테트로미노는 반드시 한 정사각형이 정확히 하나의 칸을 포함하도록 놓아야 하며, 회전이나 대칭을 시켜도 된다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 종이의 세로 크기 N과 가로 크기 M이 주어진다. (4&nbsp;≤ N, M ≤ 500)</p>



<p class="has-medium-font-size">둘째 줄부터 N개의 줄에 종이에 쓰여 있는 수가 주어진다. </p>



<p class="has-medium-font-size">i번째 줄의 j번째 수는 위에서부터 i번째 칸, 왼쪽에서부터 j번째 칸에 쓰여 있는 수이다. </p>



<p class="has-medium-font-size">입력으로 주어지는 수는 1,000을 넘지 않는 자연수이다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 테트로미노가 놓인 칸에 쓰인 수들의 합의 최댓값을 출력한다.</p>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<ul class="wp-block-list">
<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/appie701" target="_blank" rel="noreferrer noopener">appie701</a>, <a href="https://www.acmicpc.net/user/crookid" target="_blank" rel="noreferrer noopener">crookid</a>, <a href="https://www.acmicpc.net/user/esuperstar" target="_blank" rel="noreferrer noopener">esuperstar</a>, <a href="https://www.acmicpc.net/user/raboribus" target="_blank" rel="noreferrer noopener">raboribus</a>, <a href="https://www.acmicpc.net/user/rlatpwlsdlek" target="_blank" rel="noreferrer noopener">rlatpwlsdlek</a>, <a href="https://www.acmicpc.net/user/stack" target="_blank" rel="noreferrer noopener">stack</a>, <a href="https://www.acmicpc.net/user/vjerksen" target="_blank" rel="noreferrer noopener">vjerksen</a></li>



<li>문제를 만든 사람: <a href="https://www.acmicpc.net/user/baekjoon">baek</a><a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">j</a><a href="https://www.acmicpc.net/user/baekjoon">oon</a></li>



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



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



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



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



<li><a href="https://www.acmicpc.net/problem/tag/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</a></li>
</ul>



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



<figure class="wp-block-image size-full"><img decoding="async" width="389" height="284" src="https://lycos7560.com/wp-content/uploads/2023/02/image-75.png" alt="" class="wp-image-33204" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-75.png 389w, https://lycos7560.com/wp-content/uploads/2023/02/image-75-300x219.png 300w" sizes="(max-width: 389px) 100vw, 389px" /></figure>



<p class="has-medium-font-size">DFS 탐색</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="283" height="161" src="https://lycos7560.com/wp-content/uploads/2023/02/image-77.png" alt="" class="wp-image-33206"/></figure>



<p class="has-medium-font-size">BFS 탐색 (나는 예외 처리로 해결)</p>



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



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



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



<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 = 500;

int map[MAX][MAX];

bool checkMap[MAX][MAX];

int N, M, result = 0;

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

void DFS_Search(int nowX, int nowY, int cnt, int val)
{
	if (cnt == 4) {
		result = max(result, val);
		return;
	}

	for (int i = 0; i &lt; 4; i++) {

		int dx = nowX + dxdy[i][0];
		int dy = nowY + dxdy[i][1];

		// 범위를 벗어나면 넘어간다.
		if (dx &lt; 0 || dy &lt; 0 || dx >= N || dy >= M) continue;
		// 방문했다면 넘어간다.
		if (checkMap[dx][dy] == true) continue;

		cnt++;
		val += map[dx][dy];
		checkMap[dx][dy] = true;
		DFS_Search(dx, dy, cnt, val);
		checkMap[dx][dy] = false;
		cnt--;
		val -= map[dx][dy];

	}
}

// 'ㅗ' 탐색을 위한 함수
void Exception_Search(int nowX, int nowY, int val)
{
	for (int i = 0; i &lt; 4; i++) {
		int dx = nowX + dxdy[i][0];
		int dy = nowY + dxdy[i][1];
		if (dx &lt; 0 || dy &lt; 0 || dx >= N || dy >= M) continue;
		val += map[dx][dy];
	}

	for (int i = 0; i &lt; 4; i++) {
		int dx = nowX + dxdy[i][0];
		int dy = nowY + dxdy[i][1];

		if (dx &lt; 0 || dy &lt; 0 || dx >= N || dy >= M) {
			result = max(result, val);
			continue;
		}

		val -= map[dx][dy];
		result = max(result, val);
		val += map[dx][dy];
	}

}


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

	cin >> N >> M;

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

	for (int i = 0; i &lt; N; i++) {
		for (int j = 0; j &lt; M; j++) {
			checkMap[i][j] = true;
			DFS_Search(i, j, 1, map[i][j]);
			checkMap[i][j] = false;
			Exception_Search(i, j, map[i][j]);
		}
	}

	cout &lt;&lt; result;

	return 0;
}</pre>



<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/02/image-74.png" alt="" class="wp-image-33198" width="877" height="150" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-74.png 746w, https://lycos7560.com/wp-content/uploads/2023/02/image-74-300x51.png 300w" sizes="(max-width: 877px) 100vw, 877px" /></figure>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1292" height="646" src="https://lycos7560.com/wp-content/uploads/2023/02/image-79.png" alt="" class="wp-image-33209" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-79.png 1292w, https://lycos7560.com/wp-content/uploads/2023/02/image-79-300x150.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-79-768x384.png 768w" sizes="(max-width: 1292px) 100vw, 1292px" /></figure>



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



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



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



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">6 10
3 3 6 4 1 4 8 5 3 2
9 5 1 2 4 1 9 9 5 5
2 5 1 2 3 3 3 7 6 4
1 6 5 6 4 7 4 7 7 4
3 8 5 9 6 4 2 6 1 1
6 3 3 7 1 2 2 2 8 4</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="">33</pre>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4 4
1 1 1 1
2 1000 1 1
1 1000 2 1
1 1 1 1</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="">2004</pre>



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



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



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

4 4
0 0 0 1
0 0 0 2
0 0 0 3
0 0 0 4

4 4
0 0 0 0
0 0 0 0
0 0 1 2
0 0 3 4

4 4
0 0 0 0
0 0 1 0
0 0 2 0
0 0 3 4

4 4
0 0 0 0
0 0 0 0
0 1 2 3
0 4 0 0

4 4
0 0 0 0
0 0 1 2
0 0 0 3
0 0 0 4

4 4
0 0 0 0
0 0 0 0
0 0 0 1
0 4 3 2

4 4
0 0 0 0
0 0 0 1
0 0 0 2
0 0 4 3

4 4
0 0 0 0
0 0 0 0
0 1 0 0
0 2 3 4

4 4
0 0 0 0
0 0 2 1
0 0 3 0
0 0 4 0

4 4
0 0 0 0
0 0 0 0
0 1 2 3
0 0 0 4

4 4
0 0 0 0
0 0 0 1
0 0 2 3
0 0 4 0

4 4
0 0 0 0
0 0 1 0
0 0 2 3
0 0 0 4

4 4
0 0 0 0
0 0 0 0
0 1 2 0
0 0 3 4

4 4
0 0 0 0
0 0 0 0
0 0 3 4
0 1 2 0

4 4
0 0 0 0
0 0 0 1
0 0 2 3
0 0 0 4

4 4
0 0 0 0
0 0 1 0
0 0 2 3
0 0 4 0

4 4
0 0 0 0
0 0 0 0
0 0 1 0
0 2 3 4

4 4
0 0 0 0
0 0 0 0
0 1 2 3
0 0 4 0</pre>



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



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



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



<div style="height:60px" 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-14500%eb%b2%88-%ed%85%8c%ed%8a%b8%eb%a1%9c%eb%af%b8%eb%85%b8-c-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33194/">백준 14500번 (테트로미노, 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-14500%eb%b2%88-%ed%85%8c%ed%8a%b8%eb%a1%9c%eb%af%b8%eb%85%b8-c-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33194/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 17626번 (Four Squares 4, C++, DP) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17626%eb%b2%88-four-squares-4-c-baekjoon/5731/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17626%eb%b2%88-four-squares-4-c-baekjoon/5731/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 30 Jan 2023 06:50:46 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[17626]]></category>
		<category><![CDATA[17626번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[Four Squares 4]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 17626]]></category>
		<category><![CDATA[백준 17626번]]></category>
		<category><![CDATA[브루트 포스]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5731</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 17626번 'Four Squares 4' 문제에 대한 글입니다. '다이나믹 프로그래밍' 알고리즘을 이용하여 해결하였습니다. (This is an article on the question of 'Four Squares 4' in BAEKJOON No. 17626 It was solved using the 'Dynamic Programming' algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17626%eb%b2%88-four-squares-4-c-baekjoon/5731/">백준 17626번 (Four Squares 4, C++, DP) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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



<h1 class="wp-block-heading">Four Squares 4</h1>



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



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



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">0.5 초</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">17028</td><td class="has-text-align-left" data-align="left">7537</td><td class="has-text-align-left" data-align="left">5916</td><td class="has-text-align-left" data-align="left">44.794%</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">라그랑주는 1770년에 모든 자연수는 넷 혹은 그 이하의 제곱수의 합으로 표현할 수 있다고 증명하였다. </p>



<p class="has-medium-font-size">어떤 자연수는 복수의 방법으로 표현된다. </p>



<p class="has-medium-font-size">예를 들면, 26은 5<sup>2</sup>과 1<sup>2</sup>의 합이다; 또한 4<sup>2</sup> + 3<sup>2</sup> + 1<sup>2</sup>으로 표현할 수도 있다. </p>



<p class="has-medium-font-size">역사적으로 암산의 명수들에게 공통적으로 주어지는 문제가 </p>



<p class="has-medium-font-size">바로 자연수를 넷 혹은 그 이하의 제곱수 합으로 나타내라는 것이었다. </p>



<p class="has-medium-font-size">1900년대 초반에 한 암산가가 15663 = 125<sup>2</sup> + 6<sup>2</sup> + 1<sup>2</sup> + 1<sup>2</sup>라는 해를 구하는데 8초가 걸렸다는 보고가 있다. </p>



<p class="has-medium-font-size">좀 더 어려운 문제에 대해서는 56초가 걸렸다: 11339 = 105<sup>2</sup> + 15<sup>2</sup> + 8<sup>2</sup> + 5<sup>2</sup>.</p>



<p class="has-medium-font-size">자연수&nbsp;<em>n</em>이 주어질 때,&nbsp;<em>n</em>을 최소 개수의 제곱수 합으로 표현하는 컴퓨터 프로그램을 작성하시오.</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">입력은 표준입력을 사용한다. 입력은 자연수 <em>n</em>을 포함하는 한 줄로 구성된다. </p>



<p class="has-medium-font-size">여기서, 1 ≤ <em>n</em> ≤ 50,000이다.</p>



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



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



<p class="has-medium-font-size">출력은 표준출력을 사용한다. </p>



<p class="has-medium-font-size">합이 <em>n</em>과 같게 되는 제곱수들의 최소 개수를 한 줄에 출력한다.</p>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<p><a href="https://www.acmicpc.net/category/1">I</a><a href="https://www.acmicpc.net/category/1" target="_blank" rel="noreferrer noopener">C</a><a href="https://www.acmicpc.net/category/1">PC</a> > <a href="https://www.acmicpc.net/category/7" target="_blank" rel="noreferrer noopener">Regionals</a> > <a href="https://www.acmicpc.net/category/42" target="_blank" rel="noreferrer noopener">Asia Pacific</a> > <a href="https://www.acmicpc.net/category/211" target="_blank" rel="noreferrer noopener">Korea</a> > <a href="https://www.acmicpc.net/category/256" target="_blank" rel="noreferrer noopener">Nationwide Internet Competition</a> > <a href="https://www.acmicpc.net/category/detail/2064" target="_blank" rel="noreferrer noopener">Seoul Nationalwide Internet Competition 2019</a> H번</p>



<ul class="wp-block-list">
<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/tktj12" target="_blank" rel="noreferrer noopener">tktj12</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/25" target="_blank" rel="noreferrer noopener">다이나믹 프로그래밍</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</a></li>
</ul>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1600" height="1469" src="https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230130_154139671.jpg" alt="" class="wp-image-5732" srcset="https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230130_154139671.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230130_154139671-300x275.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230130_154139671-768x705.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230130_154139671-1536x1410.jpg 1536w" sizes="(max-width: 1600px) 100vw, 1600px" /></figure>



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



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



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



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

using namespace std;

int N;

int dp[50001];

int main()
{
	cin >> N;

	dp[1] = 1;

	for (int i = 2; i &lt;= N; i++) {
		int minN = INT32_MAX;
		for (int j = 1; j * j &lt;= i; j++) { // 모든 경우의 수를 확인
			int tmp = i - j * j;
			minN = min(minN, dp[tmp]);
		}
		dp[i] = minN + 1;
	}

	cout &lt;&lt; dp[N];

	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/01/image-39.png" alt="" class="wp-image-5733" width="1326" height="120" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-39.png 1030w, https://lycos7560.com/wp-content/uploads/2023/01/image-39-300x27.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-39-768x69.png 768w" sizes="(max-width: 1326px) 100vw, 1326px" /></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-17626%eb%b2%88-four-squares-4-c-baekjoon/5731/">백준 17626번 (Four Squares 4, C++, DP) [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-17626%eb%b2%88-four-squares-4-c-baekjoon/5731/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1107번 (리모컨, C++, Brute Force) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1107%eb%b2%88-%eb%a6%ac%eb%aa%a8%ec%bb%a8-c-brute-force-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5678/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1107%eb%b2%88-%eb%a6%ac%eb%aa%a8%ec%bb%a8-c-brute-force-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5678/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 27 Jan 2023 17:25:46 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1107]]></category>
		<category><![CDATA[1107번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[리모컨]]></category>
		<category><![CDATA[반례]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1107]]></category>
		<category><![CDATA[백준 1107번]]></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=5678</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1107번 '리모컨' 문제에 대한 글입니다. 'Brute Force' 알고리즘을 이용하여 해결하였습니다.<br />
(This is an article about the 'remote control' problem in BAEKJOON 1107. Solved using the 'Brute Force' algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1107%eb%b2%88-%eb%a6%ac%eb%aa%a8%ec%bb%a8-c-brute-force-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5678/">백준 1107번 (리모컨, C++, Brute Force) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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



<h1 class="wp-block-heading">리모컨</h1>



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



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



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">2 초</td><td class="has-text-align-left" data-align="left">256 MB</td><td class="has-text-align-left" data-align="left">82926</td><td class="has-text-align-left" data-align="left">20011</td><td class="has-text-align-left" data-align="left">13910</td><td class="has-text-align-left" data-align="left">22.624%</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">수빈이는 TV를 보고 있다. 수빈이는 채널을 돌리려고 했지만, 버튼을 너무 세게 누르는&nbsp;바람에, 일부 숫자 버튼이 고장났다.</p>



<p class="has-medium-font-size">리모컨에는 버튼이 0부터 9까지 숫자, +와 -가 있다. +를 누르면 현재 보고있는 채널에서 +1된 채널로 이동하고, </p>



<p class="has-medium-font-size">-를 누르면 -1된 채널로 이동한다. 채널 0에서 -를 누른 경우에는 채널이 변하지 않고, 채널은 무한대 만큼 있다.</p>



<p class="has-medium-font-size">수빈이가 지금 이동하려고 하는 채널은 N이다. 어떤 버튼이 고장났는지 주어졌을 때, </p>



<p class="has-medium-font-size">채널 N으로 이동하기 위해서 버튼을 최소 몇 번 눌러야하는지 구하는 프로그램을 작성하시오. </p>



<p class="has-medium-font-size">수빈이가 지금 보고 있는 채널은 100번이다.</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 (0 ≤ N ≤ 500,000)이 주어진다.  </p>



<p class="has-medium-font-size">둘째 줄에는 고장난 버튼의 개수 M (0 ≤ M ≤ 10)이 주어진다. </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으로 이동하기 위해 버튼을 최소 몇 번 눌러야 하는지를 출력한다.</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="">5457
3
6 7 8</pre>



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



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



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



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



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



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



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



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



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



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">500000
8
0 2 3 4 6 7 8 9</pre>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1
9
1 2 3 4 5 6 7 8 9</pre>



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



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



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



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



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



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



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



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



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">140200
3
4 5 6</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="">207</pre>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1555
3
0 1 9</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="">670</pre>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">99999
9
0 2 3 4 5 6 7 8 9</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="">11118</pre>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">50000
9
0 1 2 3 4 5 6 7 8</pre>



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



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



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



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">139133
7
9 6 8 2 1 5 7</pre>



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



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



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



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



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



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



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



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



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



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



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



<p class="has-medium-font-size">예제 1의 경우 5455++ 또는 5459&#8211;</p>



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



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



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



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



<li>잘못된 조건을 찾은 사람: <a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</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/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</a></li>
</ul>



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



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



<p class="has-medium-font-size">아래에서 위로 올라가는 방법도 있지만 위에서 아래로 내려가는 방법도 같이 생각해야한다.</p>



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



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



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



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

using namespace std;

bool arr[10];

string str, strTemp;

int N, M, temp, cnt, target, result = INT32_MAX;

void dfs(string st, char ch)
{
	if (st.length() == str.length() + 1) return;
	st.push_back(ch);
	cnt = abs(target - atoi(st.c_str())) + st.length();
	result = min(cnt, result);

	for (int i = 0; i &lt; 10; i++) {
		if (arr[i] == true) continue;
		dfs(st, i + '0');
	}
}

int main()
{
	cin >> str >> M;

	target = atoi(str.c_str());

	for (int i = 0; i &lt; M; i++) {
		cin >> temp;
		arr[temp] = true;
	}
	
	for (int i = 0; i &lt; 10; i++) {
		if (arr[i] == true) continue;
		dfs(strTemp, i + '0');
	}

	result = min(abs(target - 100), result);

	cout &lt;&lt; result;

	return 0;
}</pre>



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



<p class="has-medium-font-size">문자열로 접근하니까 속도가 너무 느리다&#8230;.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1245" height="160" src="https://lycos7560.com/wp-content/uploads/2023/01/image-30.png" alt="" class="wp-image-5679" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-30.png 1245w, https://lycos7560.com/wp-content/uploads/2023/01/image-30-300x39.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-30-768x99.png 768w" sizes="(max-width: 1245px) 100vw, 1245px" /></figure>



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



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1107%eb%b2%88-%eb%a6%ac%eb%aa%a8%ec%bb%a8-c-brute-force-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5678/">백준 1107번 (리모컨, C++, Brute Force) / 추가 반례 [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-1107%eb%b2%88-%eb%a6%ac%eb%aa%a8%ec%bb%a8-c-brute-force-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5678/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1436번 (영화감독 숌, C++, brute force) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/1436-film-director-shom-c-brute-force-baekjoon/4530/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/1436-film-director-shom-c-brute-force-baekjoon/4530/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 13 Jan 2023 19:14:50 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1436]]></category>
		<category><![CDATA[1436번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></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[백준 1436]]></category>
		<category><![CDATA[백준 1436번]]></category>
		<category><![CDATA[브루트 포스]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[영화감독 숌]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=4530</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1436번 '영화감독 숌' 문제에 대한 글입니다. "brute force" 알고리즘을 이용하여 해결하였습니다. (This is BAEKJOON's 1436 'Film Director Shom' issue. Solved using the "brute force" algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/1436-film-director-shom-c-brute-force-baekjoon/4530/">백준 1436번 (영화감독 숌, C++, brute force) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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



<h1 class="wp-block-heading">영화감독 숌</h1>



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



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



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



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



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



<p class="has-medium-font-size">666은 종말을 나타내는 숫자라고 한다. </p>



<p class="has-medium-font-size">따라서, 많은 블록버스터 영화에서는 666이 들어간 제목을 많이 사용한다. </p>



<p class="has-medium-font-size">영화감독 숌은 세상의 종말 이라는 시리즈 영화의 감독이다. </p>



<p class="has-medium-font-size">조지 루카스는 스타워즈를 만들 때, 스타워즈 1, 스타워즈 2, 스타워즈 3, 스타워즈 4, 스타워즈 5, 스타워즈 6과 같이 이름을 지었고, </p>



<p class="has-medium-font-size">피터 잭슨은 반지의 제왕을 만들 때, 반지의 제왕 1, 반지의 제왕 2, 반지의 제왕 3과 같이 영화 제목을 지었다.</p>



<p class="has-medium-font-size">하지만 숌은 자신이 조지 루카스와 피터 잭슨을 뛰어넘는다는 것을 보여주기 위해서 영화 제목을 좀 다르게 만들기로 했다.</p>



<p class="has-medium-font-size">종말의 숫자란 어떤 수에 6이 적어도 3개이상 연속으로 들어가는 수를 말한다. </p>



<p class="has-medium-font-size">제일 작은 종말의 숫자는 666이고, 그 다음으로 큰 수는 1666, 2666, 3666, &#8230;. 과 같다.</p>



<p class="has-medium-font-size">따라서, 숌은 첫 번째 영화의 제목은 세상의 종말 666, 두 번째 영화의 제목은 세상의 종말 1666 이렇게 이름을 지을 것이다. </p>



<p class="has-medium-font-size">일반화해서 생각하면, N번째 영화의 제목은 세상의 종말 (N번째로 작은 종말의 숫자) 와 같다.</p>



<p class="has-medium-font-size">숌이 만든 N번째 영화의 제목에 들어간 숫자를 출력하는 프로그램을 작성하시오. </p>



<p class="has-medium-font-size">숌은 이 시리즈를 항상 차례대로 만들고, 다른 영화는 만들지 않는다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 숫자 N이 주어진다. </p>



<p class="has-medium-font-size">N은 10,000보다 작거나 같은 자연수이다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 N번째 영화의 제목에 들어간 수를 출력한다.</p>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</a></li>
</ul>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1600" height="502" src="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230114_041030983.jpg" alt="" class="wp-image-4533" srcset="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230114_041030983.jpg 1600w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230114_041030983-300x94.jpg 300w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230114_041030983-768x241.jpg 768w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230114_041030983-1536x482.jpg 1536w" sizes="(max-width: 1600px) 100vw, 1600px" /></figure>



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



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



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



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

using namespace std;

int N, cnt, number, tempNumber;

string str;

int main()
{
	cin >> N;
	cnt = 0;
	number = 665;
	tempNumber = 0;

	// N번째가 나올 떄까지 반복
	while (cnt != N) {
		number++;
		tempNumber = number;

		while (tempNumber != 0)
		{
			if (tempNumber % 1000 == 666) {
				cnt++;
				break;
			}
			else tempNumber /= 10;
		}
	}

	cout &lt;&lt; number;

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1034" height="101" src="https://lycos7560.com/wp-content/uploads/image-936.png" alt="" class="wp-image-4531" srcset="https://lycos7560.com/wp-content/uploads/image-936.png 1034w, https://lycos7560.com/wp-content/uploads/image-936-300x29.png 300w, https://lycos7560.com/wp-content/uploads/image-936-768x75.png 768w" sizes="(max-width: 1034px) 100vw, 1034px" /></figure>



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



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/1436-film-director-shom-c-brute-force-baekjoon/4530/">백준 1436번 (영화감독 숌, C++, brute force) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/1436-film-director-shom-c-brute-force-baekjoon/4530/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 7568번 (덩치, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/7568-large-figure-c-baekjoon/4516/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/7568-large-figure-c-baekjoon/4516/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 13 Jan 2023 16:26:52 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[7568]]></category>
		<category><![CDATA[7568번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[덩치]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 7568]]></category>
		<category><![CDATA[백준 7568번]]></category>
		<category><![CDATA[브루트 포스]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=4516</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 7568번 '덩치' 문제에 대한 글입니다. (This is BAEKJOON's 7568 article on the 'large figure' problem.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/7568-large-figure-c-baekjoon/4516/">백준 7568번 (덩치, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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



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



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



<div style="height:36px" 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">어떤 사람의 몸무게가 x kg이고 키가 y cm라면 이 사람의 덩치는 (x, y)로 표시된다. </p>



<p class="has-medium-font-size">두 사람 A 와 B의 덩치가 각각 (x, y), (p, q)라고 할 때 x > p 그리고 y > q 이라면 </p>



<p class="has-medium-font-size">우리는 A의 덩치가 B의 덩치보다 &#8220;더 크다&#8221;고 말한다. </p>



<p class="has-medium-font-size">예를 들어 어떤 A, B 두 사람의 덩치가 각각 (56, 177), (45, 165) 라고 한다면 A의 덩치가 B보다 큰 셈이 된다. </p>



<p class="has-medium-font-size">그런데 서로 다른 덩치끼리 크기를 정할 수 없는 경우도 있다. </p>



<p class="has-medium-font-size">예를 들어 두 사람 C와 D의 덩치가 각각 (45, 181), (55, 173)이라면 몸무게는 D가 C보다 더 무겁고, </p>



<p class="has-medium-font-size">키는 C가 더 크므로, &#8220;덩치&#8221;로만 볼 때 C와 D는 누구도 상대방보다 더 크다고 말할 수 없다.</p>



<p class="has-medium-font-size">N명의 집단에서 각 사람의 덩치 등수는 자신보다 더 &#8220;큰 덩치&#8221;의 사람의 수로 정해진다. </p>



<p class="has-medium-font-size">만일 자신보다 더 큰 덩치의 사람이 k명이라면 그 사람의 덩치 등수는 k+1이 된다. </p>



<p class="has-medium-font-size">이렇게 등수를 결정하면 같은 덩치 등수를 가진 사람은 여러 명도 가능하다. </p>



<p class="has-medium-font-size">아래는 5명으로 이루어진 집단에서 각 사람의 덩치와 그 등수가 표시된 표이다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="737" height="435" src="https://lycos7560.com/wp-content/uploads/image-933.png" alt="" class="wp-image-4517" srcset="https://lycos7560.com/wp-content/uploads/image-933.png 737w, https://lycos7560.com/wp-content/uploads/image-933-300x177.png 300w" sizes="(max-width: 737px) 100vw, 737px" /></figure>



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



<p class="has-medium-font-size">위 표에서 C보다 더 큰 덩치의 사람이 없으므로 C는 1등이 된다. </p>



<p class="has-medium-font-size">그리고 A, B, D 각각의 덩치보다 큰 사람은 C뿐이므로 이들은 모두 2등이 된다. </p>



<p class="has-medium-font-size">그리고 E보다 큰 덩치는 A, B, C, D 이렇게 4명이므로 E의 덩치는 5등이 된다. </p>



<p class="has-medium-font-size">위 경우에 3등과 4등은 존재하지 않는다. </p>



<p class="has-medium-font-size">여러분은 학생 N명의 몸무게와 키가 담긴 입력을 읽어서 각 사람의 덩치 등수를 계산하여 출력해야 한다.</p>



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



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



<p class="has-medium-font-size">첫 줄에는 전체 사람의 수 N이 주어진다. </p>



<p class="has-medium-font-size">그리고 이어지는 N개의 줄에는 각 사람의 몸무게와 키를 나타내는 양의 정수 x와 y가 하나의 공백을 두고 각각 나타난다.</p>



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



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



<p class="has-medium-font-size">여러분은 입력에 나열된 사람의 덩치 등수를 구해서 그 순서대로 첫 줄에 출력해야 한다. </p>



<p class="has-medium-font-size">단, 각 덩치 등수는 공백 문자로 분리되어야 한다.</p>



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



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



<ul class="wp-block-list">
<li>2 ≤ N ≤ 50</li>



<li>10 ≤ x, y ≤ 200</li>
</ul>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5
55 185
58 183
88 186
60 175
46 155</pre>



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



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



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



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



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



<p><a href="https://www.acmicpc.net/category/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/214" target="_blank" rel="noreferrer noopener">지역본선 2013</a> > <a href="https://www.acmicpc.net/category/detail/912" target="_blank" rel="noreferrer noopener">초등부</a> 2번</p>



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



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



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



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



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



<li><a href="https://www.acmicpc.net/problem/tag/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</a></li>
</ul>



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



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



<p class="has-medium-font-size">사람의 수는 N 이므로 비교할 수 있는 모든 경우를 비교하여 등수를 매겼다.</p>



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



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



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



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

using namespace std;

int weight[51], height[51], ranks[51];

int N, temp;

int main()
{
	cin >> N;
	for (int i = 1; i &lt;= N; i++) {
		cin >> weight[i] >> height[i];
	}

	for (int i = 1; i &lt;= N; i++) {

		// 순위는 N등 부터 시작
		temp = N;

		for (int j = 1; j &lt;= N ; j++) {
			
			// 자기 자신과 비교할 경우에는 넘어간다.
			if (i == j) { continue; }

			// 비교 기준의 무게가 더 크거나 같을 경우 rank 상승
			// 비교 기준의 키가 더 크거나 같을 경우 rank 상승
			if (weight[i] >= weight[j]) temp--;
			else if (height[i] >= height[j]) temp--;
		}

		ranks[i] = temp;
	}

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

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1034" height="148" src="https://lycos7560.com/wp-content/uploads/image-934.png" alt="" class="wp-image-4518" srcset="https://lycos7560.com/wp-content/uploads/image-934.png 1034w, https://lycos7560.com/wp-content/uploads/image-934-300x43.png 300w, https://lycos7560.com/wp-content/uploads/image-934-768x110.png 768w" sizes="(max-width: 1034px) 100vw, 1034px" /></figure>



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



<p class="has-medium-font-size">키나 몸무게가 같을 경우에도 등수에 영향을 미친다는 것을 제출하고 확인</p>



<div style="height:52px" 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/7568-large-figure-c-baekjoon/4516/">백준 7568번 (덩치, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/7568-large-figure-c-baekjoon/4516/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1075번 (나누기, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1075%eb%b2%88-%eb%82%98%eb%88%84%ea%b8%b0-c-baekjoon/33894/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1075%eb%b2%88-%eb%82%98%eb%88%84%ea%b8%b0-c-baekjoon/33894/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 11 Jan 2023 09:07:20 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1075]]></category>
		<category><![CDATA[1075번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[나누기]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1075]]></category>
		<category><![CDATA[백준 1075번]]></category>
		<category><![CDATA[브루트 포스]]></category>
		<category><![CDATA[수학]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=33894</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1075번 '나누기' 문제에 대한 글입니다.<br />
브루트포스 알고리즘을 이용하여 해결하였습니다.  (This is an article about the 'sharing' problem in BAEKJOON No. 1075.<br />
It was solved using the Brute algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1075%eb%b2%88-%eb%82%98%eb%88%84%ea%b8%b0-c-baekjoon/33894/">백준 1075번 (나누기, 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-bef1ada2      "
					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/1075" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1075</a></p>



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



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



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



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



<p class="has-medium-font-size">두 정수 N과 F가 주어진다. </p>



<p class="has-medium-font-size">지민이는 정수 N의 가장 뒤 두 자리를 적절히 바꿔서 N을 F로 나누어 떨어지게 만들려고 한다. </p>



<p class="has-medium-font-size">만약 가능한 것이 여러 가지이면, 뒤 두 자리를 가능하면 작게 만들려고 한다.</p>



<p class="has-medium-font-size">예를 들어, N=275이고, F=5이면, 답은 00이다. 200이 5로 나누어 떨어지기 때문이다. </p>



<p class="has-medium-font-size">N=1021이고, F=11이면, 정답은 01인데, 1001이 11로 나누어 떨어지기 때문이다.</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, 둘째 줄에 F가 주어진다. </p>



<p class="has-medium-font-size">N은 100보다 크거나 같고, 2,000,000,000보다 작거나 같은 자연수이다. </p>



<p class="has-medium-font-size">F는 100보다 작거나 같은 자연수이다.</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">한자리이면 앞에 0을 추가해서 두 자리로 만들어야 한다.</p>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<li>문제의 오타를 찾은 사람: <a href="https://www.acmicpc.net/user/eric00513" target="_blank" rel="noreferrer noopener">eric00513</a></li>



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



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



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



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



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



<p class="has-medium-font-size">부루트포스 알고리즘을 이용하여 00 부터 99 까지 모든 경우의 수를 확인한다.</p>



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



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

using namespace std;

int main()
{
	int N, F, result;
	cin >> N >> F;

	result = INT32_MAX;
	for (int i = 99; i >= 0; i--) {
		if ((((N / 100) * 100) + i) % F == 0) result = i;
	}
	string str;
	str = to_string(result);
	if (str.length() == 1) str.insert(0, "0");
	cout &lt;&lt; str;

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1037" height="100" src="https://lycos7560.com/wp-content/uploads/2023/03/image-42.png" alt="" class="wp-image-33896" srcset="https://lycos7560.com/wp-content/uploads/2023/03/image-42.png 1037w, https://lycos7560.com/wp-content/uploads/2023/03/image-42-300x29.png 300w, https://lycos7560.com/wp-content/uploads/2023/03/image-42-768x74.png 768w" sizes="(max-width: 1037px) 100vw, 1037px" /></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>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1075%eb%b2%88-%eb%82%98%eb%88%84%ea%b8%b0-c-baekjoon/33894/">백준 1075번 (나누기, 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-1075%eb%b2%88-%eb%82%98%eb%88%84%ea%b8%b0-c-baekjoon/33894/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
