<?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>백준 2108번 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/%eb%b0%b1%ec%a4%80-2108%eb%b2%88/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Thu, 23 Feb 2023 00:01:41 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://lycos7560.com/wp-content/uploads/2022/11/cropped-cropped-cropped-log-1-150x150-1-80x80.png</url>
	<title>백준 2108번 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>백준 2108번 (통계학, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/2108-statistics-c-binarysearch-baekjoon/4578/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/2108-statistics-c-binarysearch-baekjoon/4578/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 15 Jan 2023 20:33:09 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2108]]></category>
		<category><![CDATA[2108번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 2108]]></category>
		<category><![CDATA[백준 2108번]]></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=4578</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 2108번 "통계학" 문제에 대한 글입니다. (This article is about the "Statistics" problem in BAEKJOON No. 2108.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/2108-statistics-c-binarysearch-baekjoon/4578/">백준 2108번 (통계학, 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>



<h2 class="wp-block-heading">통계학</h2>



<p class="has-medium-font-size wp-block-paragraph"><a href="https://www.acmicpc.net/problem/2108">https://www.acmicpc.net/problem/2108</a></p>



<div style="height:41px" 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">124496</td><td class="has-text-align-left" data-align="left">27685</td><td class="has-text-align-left" data-align="left">22260</td><td class="has-text-align-left" data-align="left">25.422%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size wp-block-paragraph">수를 처리하는 것은 통계학에서 상당히 중요한 일이다. </p>



<p class="has-medium-font-size wp-block-paragraph">통계학에서 N개의 수를 대표하는 기본 통계 값에는 다음과 같은 것들이 있다. </p>



<p class="has-medium-font-size wp-block-paragraph">단, N은 홀수라고 가정하자.</p>



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



<ol class="wp-block-list">
<li>산술평균 : N개의 수들의 합을 N으로 나눈 값</li>



<li>중앙값 : N개의 수들을 증가하는 순서로 나열했을 경우 그 중앙에 위치하는 값</li>



<li>최빈값 : N개의 수들 중 가장 많이 나타나는 값</li>



<li>범위 : N개의 수들 중 최댓값과 최솟값의 차이</li>
</ol>



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



<p class="has-medium-font-size wp-block-paragraph">N개의 수가 주어졌을 때, </p>



<p class="has-medium-font-size wp-block-paragraph">네 가지 기본 통계값을 구하는 프로그램을 작성하시오.</p>



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



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



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



<p class="has-medium-font-size wp-block-paragraph">단, N은 홀수이다. 그 다음 N개의 줄에는 정수들이 주어진다. </p>



<p class="has-medium-font-size wp-block-paragraph">입력되는 정수의 절댓값은 4,000을 넘지 않는다.</p>



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



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



<p class="has-medium-font-size wp-block-paragraph">첫째 줄에는 산술평균을 출력한다. </p>



<p class="has-medium-font-size wp-block-paragraph">소수점 이하 첫째 자리에서 반올림한 값을 출력한다.</p>



<p class="has-medium-font-size wp-block-paragraph">둘째 줄에는 중앙값을 출력한다.</p>



<p class="has-medium-font-size wp-block-paragraph">셋째 줄에는 최빈값을 출력한다. </p>



<p class="has-medium-font-size wp-block-paragraph">여러 개 있을 때에는 최빈값 중 두 번째로 작은 값을 출력한다.</p>



<p class="has-medium-font-size wp-block-paragraph">넷째 줄에는 범위를 출력한다.</p>



<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
1
3
8
-2
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="">2
2
1
10</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="">1
4000</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="">4000
4000
4000
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="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5
-1
-2
-3
-1
-2</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="">-2
-2
-1
2</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="">3
0
0
-1</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="">0
0
0
1</pre>



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



<p class="has-medium-font-size wp-block-paragraph">(0 + 0 + (-1)) / 3 = -0.333333&#8230; 이고 이를 첫째 자리에서 반올림하면 0이다. -0으로 출력하면 안된다.</p>



<div style="height:44px" 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/bjh3502" target="_blank" rel="noreferrer noopener">bjh3502</a>, <a href="https://www.acmicpc.net/user/bsyun0571" target="_blank" rel="noreferrer noopener">bsyun0571</a>, <a href="https://www.acmicpc.net/user/djm03178" target="_blank" rel="noreferrer noopener">djm03178</a>, <a href="https://www.acmicpc.net/user/jungyh1509" target="_blank" rel="noreferrer noopener">jungyh1509</a>, <a href="https://www.acmicpc.net/user/palilo" target="_blank" rel="noreferrer noopener">palilo</a>, <a href="https://www.acmicpc.net/user/YunGoon" target="_blank" rel="noreferrer noopener">YunGoon</a></li>



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



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



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



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



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



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



<div style="height:37px" 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 wp-block-paragraph">최빈값이 여러 개 있을 때에는 최빈값 중 두 번째로 작은 값을 출력하는 부분을 구현하느냐고 엄청 시간이 걸렸다.</p>



<p class="has-medium-font-size wp-block-paragraph">최빈값이 같으면 리스트에 넣어서 순서를 계산하는 방식으로 처리했다.</p>



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



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



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

using namespace std;

int N, tempI, tempK, temp, tempJ;
int arr[500001];
int number[8001];
long long int sumAll;
list&lt;float> myList; // 결과를 저장할 리스트
list&lt;float> myList2; 

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

	cin >> N;
	for (int i = 0; i &lt; N; i++) {
		cin >> arr[i]; // N만큼 입력을 받음
		if (arr[i] > 0) number[arr[i] + 4000]++; // 양수일 경우
		else number[arr[i] * -1]++;
	}
		
	for (int i = 0; i &lt; N; i++)  // 총합을 구함
		sumAll = sumAll + arr[i];

	// 1. 산술평균 : N개의 수들의 합을 N으로 나눈 값
	float tempN = sumAll;
	myList.push_back(floor((tempN / N) + 0.5));

	// 2. 중앙값 : N개의 수들을 증가하는 순서로 나열했을 경우 그 중앙에 위치하는 값
	sort(arr, arr + N); // 오름차순 정렬

	myList.push_back(arr[(0 + (N))/2]);

	// 3. 최빈값 : N개의 수들 중 가장 많이 나타나는 값
	tempK = 0, tempI = -9999, tempJ = 0;
	int first = 0, second = 0;
	for (int i = 0; i &lt; 8001; i++) {
		if (i &lt;= 4000) {
			if (number[i] > tempI ) {
				tempI = number[i];
				tempK = i * -1;
				myList2.clear();
				myList2.push_back(tempK);
			}
			else if (number[i] == tempI) {
				tempK = i * -1;
				myList2.push_back(tempK);
			}
		}
		else {
				if (number[i] > tempI) {
					tempI = number[i];
					tempN = i - 4000;
					myList2.clear();
					myList2.push_back(tempN);
				}
				else if (number[i] == tempI) {
					tempK = i - 4000;
					myList2.push_back(tempK);
				}
		}
	}

	myList2.sort();

	int size = myList2.size();
	int cnt = 0;

	if (size >= 2) cnt = 2;
	else cnt = 1;

	for (auto it = myList2.begin(); it != myList2.end(); it++) {
		cnt--;
		if (cnt == 0) {
			myList.push_back(*it);
			break;
		}
	}

	// 4. 범위 : N개의 수들 중 최댓값과 최솟값의 차이
	temp = arr[0] - arr[N-1];
	temp = abs(temp);
	myList.push_back(temp);


	// 결과를 출력합니다.
	for (auto it = myList.begin(); it != myList.end(); it++) {
		cout &lt;&lt; *it &lt;&lt; "\n";
	}

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1040" height="97" src="https://lycos7560.com/wp-content/uploads/image-941.png" alt="" class="wp-image-4580" srcset="https://lycos7560.com/wp-content/uploads/image-941.png 1040w, https://lycos7560.com/wp-content/uploads/image-941-300x28.png 300w, https://lycos7560.com/wp-content/uploads/image-941-768x72.png 768w" sizes="(max-width: 1040px) 100vw, 1040px" /></figure>



<div style="height:35px" 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/2108-statistics-c-binarysearch-baekjoon/4578/">백준 2108번 (통계학, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/2108-statistics-c-binarysearch-baekjoon/4578/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
