<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>ddo_h.log</title>
        <link>https://velog.io/</link>
        <description>열심히!</description>
        <lastBuildDate>Mon, 27 Sep 2021 03:23:14 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <copyright>Copyright (C) 2019. ddo_h.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/ddo_h" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[초보자를 위한 git 사용법(Mac)]]></title>
            <link>https://velog.io/@ddo_h/mac%EC%97%90%EC%84%9C-git-%EC%82%AC%EC%9A%A9%EB%B2%95</link>
            <guid>https://velog.io/@ddo_h/mac%EC%97%90%EC%84%9C-git-%EC%82%AC%EC%9A%A9%EB%B2%95</guid>
            <pubDate>Mon, 27 Sep 2021 03:23:14 GMT</pubDate>
            <description><![CDATA[<h2 id="git-clone-생성">git clone 생성</h2>
<h4 id="1-폴더-생성-후-해당-폴더-진입하기">1. 폴더 생성 후 해당 폴더 진입하기</h4>
<p>ex) repository가 /Users/사용자이름/Documents/git_myApp인 경우</p>
<pre><code>$ cd Documents
$ cd git_myApp</code></pre><h4 id="2-git-초기-설정">2. git 초기 설정</h4>
<pre><code>$ git init</code></pre><h4 id="3-프로젝트-가져오기">3. 프로젝트 가져오기</h4>
<p>url은 git/gitLab 프로젝트 메인에서 얻을 수 있음(http 선택 후 복사)</p>
<pre><code>$ git clone [URL]</code></pre><h4 id="4-원격-설정-업데이트">4. 원격 설정 업데이트</h4>
<p>local 저장소에 있는 모든 branch의 정보를 업데이트함</p>
<pre><code>$ git remote update</code></pre><h4 id="5-branch-생성-및-작업">5. branch 생성 및 작업</h4>
<p>원격, 로컬 브랜치 생성 - 원격 연동 - 작업 진행 - 원격에 업로드
branch 관련 command는 아래에 정리되어 있음</p>
<p>.</p>
<h2 id="branch-관리">branch 관리</h2>
<h4 id="일감-관련-branch-생성">일감 관련 branch 생성</h4>
<p>git/gitLab에 새로운 branch 생성 후 local branch 생성하기
원격과 local의 branch name은 통일하기</p>
<pre><code>$ git checkout -b [new branch name]</code></pre><h4 id="local-branch-remote-branch-연동">local branch, remote branch 연동</h4>
<pre><code>$ git branch —set-upstream-to origin/[branch name]</code></pre><h4 id="branch-목록">branch 목록</h4>
<p>모든 branch 목록 확인</p>
<pre><code>$ git branch -a</code></pre><p>local 항목만 확인하려면 -a 부분 제거</p>
<h4 id="branch-이동">branch 이동</h4>
<pre><code>$ git checkout [branch name]</code></pre><p>.</p>
<h2 id="수정-사항-적용">수정 사항 적용</h2>
<h4 id="현-branch-수정-사항-확인">현 branch 수정 사항 확인</h4>
<pre><code>$ git status</code></pre><h4 id="변경-부분-삭제">변경 부분 삭제</h4>
<pre><code>$ git restore [dir name]</code></pre><h4 id="변경-부분-적용">변경 부분 적용</h4>
<pre><code>$ git add [dir name]</code></pre><h4 id="변경-부분-모두-적용">변경 부분 모두 적용</h4>
<pre><code>$ git add —all</code></pre><h4 id="pull">pull</h4>
<p>원격 branch의 수정 사항 가져옴
현재 check out 된 local branch를 최신 상태로 만들어주기 때문에 <strong>merge 전 필수</strong>로 진행해야 함</p>
<pre><code>$ git pull</code></pre><h4 id="commit">commit</h4>
<p>변경 사항 저장</p>
<pre><code>$ git commit -m [commit MSG]</code></pre><h4 id="push">push</h4>
<p>원격 branch로 변경 사항 업로드</p>
<pre><code>$ git push -u origin [branch name]</code></pre><h4 id="push-취소">push 취소</h4>
<p>merge를 진행한 경우, mother branch를 먼저 취소하고 실 작업 branch를 취소해야 오류가 발생하지 않음
master branch이거나 branch protect 설정이 되어있는 경우 취소가 불가능할 수 있음</p>
<p>한 단계 이전으로 원복</p>
<pre><code>$ git reset HEAD^</code></pre><p>원격 branch에 강제로 push</p>
<pre><code>$ git push origin [branch name] -f</code></pre><h4 id="merge">merge</h4>
<p>child branch를 현재 check out 된 mother branch에 병합하는 것</p>
<pre><code>$ git merge [child branch name]</code></pre><h4 id="merge-취소">merge 취소</h4>
<p>merge 과정에서 오류가 발생하여 branch가 merging 상태일 때 사용</p>
<pre><code>git merge --abort</code></pre><h4 id="history-조회">history 조회</h4>
<pre><code>git log</code></pre><p>.</p>
<h3 id="참고">참고</h3>
<p>-폴더 경로 확인하는 방법
finder - 보기 - 경로막대 보기 - 경로막대 우클릭 - &#39;000&#39;의 경로를 복사</p>
<p>-폴더 내부로 이동, 초기 경로로 돌아오기</p>
<pre><code>$ cd 폴더이름, $ cd</code></pre><p>-복사하기, 붙여넣기</p>
<pre><code>$ cmd+C, $ cmd+V</code></pre><p>-git gui
수정된 내역 확인할 때 편함</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[iOS 신규 서명 관련]]></title>
            <link>https://velog.io/@ddo_h/iOS-%EC%8B%A0%EA%B7%9C-%EC%84%9C%EB%AA%85-%EA%B4%80%EB%A0%A8</link>
            <guid>https://velog.io/@ddo_h/iOS-%EC%8B%A0%EA%B7%9C-%EC%84%9C%EB%AA%85-%EA%B4%80%EB%A0%A8</guid>
            <pubDate>Tue, 21 Sep 2021 07:14:21 GMT</pubDate>
            <description><![CDATA[<h2 id="서론">서론</h2>
<p>iOS 15에는 업데이트된 코드 서명 형식이 필수적으로 적용되어야 함
코드 서명 형식이 적용되지 않을 경우 다음과 같은 알림과 함께 앱이 정상적으로 설치되지 않음
&quot;YourAppName&quot; Needs to be updated</p>
<h2 id="본론">본론</h2>
<p>신규 서명 형식을 적용하려면 <strong>macOS 10.14 이상</strong> 환경에서 빌드해야 함
<em>*필자는 BigSur, Xcode 12.0 환경에서 작업</em></p>
<h2 id="테스트">테스트</h2>
<h4 id="앱에-새-서명이-필요한지-확인">앱에 새 서명이 필요한지 확인</h4>
<pre><code>% codesign -dv /path/to/MyApp.app</code></pre><p>CodeDirectory v=20400 보다 작을 경우 다시 서명해야 함</p>
<h4 id="ios-150-호환-가능-기기-목록">iOS 15.0 호환 가능 기기 목록</h4>
<ul>
<li>iOS 14.0을 지원하는 기기</li>
<li>아이폰 8, 8 플러스</li>
<li>아이폰 7, 7 플러스</li>
<li>아이폰 6s, <del>6s 플러스</del></li>
<li>아이폰 SE, SE 2세대
(6s 플러스는 실제로 설치가 불가능함)<h4 id="ios-150-beta-설치">iOS 15.0 beta 설치</h4>
<a href="betaprofiles.com">betaprofiles.com</a></li>
<li><strong>데이터 백업 필수</strong><h4 id="xcode-130-beta-설치">Xcode 13.0 beta 설치</h4>
<a href="https://developer.apple.com/download/"><del>https://developer.apple.com/download/</del></a>
Xcode 13.0 beta 버전에서 빌드할 경우 iOS 15.0 beta를 타겟으로 테스트할 수 있음</li>
<li><ul>
<li>21.09.20 기준 : Xcode 13.0 정식 업데이트됨</li>
</ul>
</li>
<li><strong>beta버전은 테스트 용도</strong>로 사용, 앱 배포 시 정식 출시된 Xcode 사용 권장</li>
</ul>
<h2 id="관련-에러">관련 에러</h2>
<h4 id="failed-to-get-the-task-for-process-000">failed to get the task for process &lt;000&gt;</h4>
<p>Code Signing을 Distribution(배포)용으로 선택한 후 디버깅할 경우 발생하는 에러
배포용을 개발용 인증서로 변경할 경우 해당 오류는 해결됨
Developer(개발)용 : Simulator나 usb 디버깅
Distribution(배포)용 : ipa 생성</p>
<h4 id="macbook-m1-사용할-경우-발생하는-빌드-오류">MacBook M1 사용할 경우 발생하는 빌드 오류</h4>
<p>Xcode beta -&gt; show info -&gt; check Rosetta -&gt; 종료 후 재실행</p>
<h4 id="swift-코드-오류">swift 코드 오류</h4>
<p>beta버전에서는 object-c 프로젝트는 정상적으로 빌드되지만, swift 프로젝트는 정상적으로 빌드되지 않음 </p>
<h2 id="기타">기타</h2>
<h4 id="xcode12-13-비교">Xcode12, 13 비교</h4>
<p>같은 앱을 패키징 하더라도 DistributionSummary.plist의 구성 요소에 변화가 있었음
profile 항목에 dateExpires가 추가됨
Appversion, team Info 항목의 위치가 변경됨</p>
<h4 id="xcode-format">Xcode format</h4>
<p>Project Document -&gt; project format에 있는 항목을 Xcode 13.0-compatible로 변경하게 되면?
Xcode 12.0에서 해당 프로젝트가 정상적으로 열리지 않음
해당 설정은 앱 환경이랑 상관없이 Xcode 프로그램과 관련된 설정으로 버전을 올리게 되면 하위 버전의 xcode와 호환이 안됨</p>
<h4 id=""></h4>
<p><a href="https://www.ivanti.co.jp/en-us/blog/your-enterprise-apps-might-need-re-signing-for-ios-15-compatibility">참고 자료_invanti</a></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[테트로미노_14500]]></title>
            <link>https://velog.io/@ddo_h/%ED%85%8C%ED%8A%B8%EB%A1%9C%EB%AF%B8%EB%85%B814500</link>
            <guid>https://velog.io/@ddo_h/%ED%85%8C%ED%8A%B8%EB%A1%9C%EB%AF%B8%EB%85%B814500</guid>
            <pubDate>Thu, 05 Aug 2021 06:24:43 GMT</pubDate>
            <description><![CDATA[<p><img src="https://images.velog.io/images/ddo_h/post/2bcddd84-7bc5-4348-950c-8df42f9c955d/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-08-05%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%203.25.00.png" alt=""></p>
<h3 id="문제출처--테트로미노_14500">문제출처 : <a href="https://www.acmicpc.net/problem/14500">테트로미노_14500</a></h3>
<h3 id="파라미터-정리">파라미터 정리</h3>
<p>N,M : 주어진 필드의 크기
Map[N][M] : 각 칸의 값
출력값: 테트로미노 내부 합산의 최대값</p>
<h3 id="간략한-과정">간략한 과정</h3>
<p>5가지 도형에 대한 dr, dc 정의하기
모든 경우에 대해 한번씩 실행한 후 최대값 반환하기</p>
<h3 id="코드">코드</h3>
<p>stack 구현</p>
<pre><code>
#include &lt;iostream&gt;
#include &lt;algorithm&gt;

using namespace std;

int N,M;
int input[500][500];
bool visit[500][500] = {false,};
int answer = 0;

typedef struct point{
    int x, y;
} point;

//stack 정의
point STACK[5];
int top = -1;

point pop() {
    return STACK[top--];
}

void push(int x,int y){
    STACK[++top].x = x;
    STACK[top].y = y;
} 

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

void dfs(int n, int m, int sum, int depth){
    sum += input[n][m];

    if(depth == 1){
        answer = max(answer, sum);
        return;
    }

    push(n,m);
    visit[n][m] = true;

    for(int i = 0; i &lt; top+1; i++){
        for(int j = 0; j &lt; 4; j++){
            int nr = STACK[i].x + dArr[j][0];
            int nc = STACK[i].y + dArr[j][1];

            if(nr&lt;0 || nc&lt;0 || nr &gt; N-1 || nc &gt; M-1) continue;

            if(!visit[nr][nc]){
                dfs(nr, nc, sum, depth-1);
            }
        }
    }

    visit[n][m] = false;
    pop();

    return;
}

int main()
{
    cin &gt;&gt; N &gt;&gt; M;

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

    for(int i = 0; i &lt; N; i++){
        for(int j = 0; j &lt; M; j++){
            dfs(i, j, 0, 4);
        }
    }

    cout &lt;&lt; answer &lt;&lt; endl;

    return 0;
}</code></pre><h3 id="다른-풀이">다른 풀이</h3>
<p>vector 사용</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;vector&gt;

using namespace std;

struct loc{
    int r,c; 
};

int N,M;
int map[500][500];
bool visit[500][500] = {false,};
vector&lt;loc&gt; list;
int res = 0;

int dr[4] = {0,1,0,-1};
int dc[4] = {1,0,-1,0};

void move(int r, int c, int sum, int dis){
    sum += map[r][c];

    if(dis == 4){
        res = max(res, sum);
        return;
    }

    list.push_back({r,c});
    visit[r][c] = true;

    for(int i = 0; i &lt; list.size(); i++){
        for(int d = 0; d &lt; 4; d++){
            int nr = list[i].r + dr[d];
            int nc = list[i].c + dc[d];

            if(nr &lt; 0 || nc &lt; 0 || nr &gt; N-1 || nc &gt; M-1) continue;
            if(visit[nr][nc]) continue;

            move(nr, nc, sum, dis+1);
        }
    }

    visit[r][c] = false;
    list.pop_back();

    return;
}

int solve(){

    for(int i = 0; i &lt; N; i++){
        for(int j = 0; j &lt; M; j++){
            move(i,j,0,1);
        }
    }

    return res;
}

int main()
{
    cin &gt;&gt; N &gt;&gt; M;

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

    cout &lt;&lt; solve() &lt;&lt; endl;

    return 0;
}</code></pre><h3 id="시행착오">시행착오</h3>
<pre><code>#include &lt;iostream&gt;
#include &lt;algorithm&gt;

using namespace std;

int N,M;
int Map[500][500];
int onceBlock[2][4] = {
    {0,1,0,1}, {0,0,1,1}
};
int twiceBlock[12][4] = {
    {0,0,0,0}, {0,1,2,3},
    {0,1,2,1}, {0,0,0,1},
    {0,1,2,1}, {0,0,0,-1},
    {0,0,1,1}, {0,1,1,2},
    {0,0,0,1}, {0,1,2,2},
    {0,0,0,-1}, {0,1,2,2}
};

int calculateSum(int dr[4], int dc[4]){
    int res = 0;
    int sum = 0;
    bool flag = true;

    for(int i = 0; i &lt; N; i++){
        for(int j = 0; j &lt; M; j++){
            for(int k = 0; k &lt; 4; k++){
                int nr = i + dr[k];
                int nc = j + dc[k];

                if(nr &lt; 0 || nc &lt; 0 || nr &gt; N-1 || nc &gt; M-1){
                    flag = false;
                    continue;
                }

                sum += Map[nr][nc];
            }

            if(flag)
                res = max(res,sum);

            flag =true;
            sum = 0;
        }
    }

    return res;
}

int solve(){
    int res = 0;
    int currentSum = 0;

    res = max(res, calculateSum(onceBlock[0], onceBlock[1]));

    for(int i = 0; i &lt; 6; i++){
        res = max(res, calculateSum(twiceBlock[(i*2)], twiceBlock[(i*2)+1]));
        res = max(res, calculateSum(twiceBlock[(i*2)+1], twiceBlock[(i*2)]));
    }

    return res;
}

int main()
{
    cin &gt;&gt; N &gt;&gt; M;

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

    cout &lt;&lt; solve() &lt;&lt; endl;

    return 0;
}
</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[[Mybatis] 동적 쿼리문]]></title>
            <link>https://velog.io/@ddo_h/Mybatis-%EB%8F%99%EC%A0%81-%EC%BF%BC%EB%A6%AC%EB%AC%B8</link>
            <guid>https://velog.io/@ddo_h/Mybatis-%EB%8F%99%EC%A0%81-%EC%BF%BC%EB%A6%AC%EB%AC%B8</guid>
            <pubDate>Wed, 04 Aug 2021 03:42:32 GMT</pubDate>
            <description><![CDATA[<h3 id="1-foreach">1. foreach</h3>
<p>list 형식의 데이터를 반복문(for문)으로 돌릴 때 사용함</p>
<h4 id="코드-예시">코드 예시</h4>
<pre><code>SELECT *
FROM CODE_INFO
WHERE 1=1
AND CODE_NAME IN
&lt;foreach collection=&quot;nameList&quot; item=&quot;item&quot; index=&quot;index&quot; open=&quot;(&quot; colse=&quot;)&quot; seperator=&quot;,&quot;&gt;
    #{item}
&lt;/foreach&gt;</code></pre><h4 id="태그-설명">태그 설명</h4>
<p>collection: 전달받은 인자. List, Array 형식
item: collection의 각 인자값을 지칭
index: 0부터 순차적으로 증가
open: for문 시작 시 삽입할 문자열
close: for문 종료 시 삽입할 문자열
separator: 각 구문 사이에 삽입할 문자열</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[연산자 오버로딩]]></title>
            <link>https://velog.io/@ddo_h/%EC%97%B0%EC%82%B0%EC%9E%90-%EC%98%A4%EB%B2%84%EB%A1%9C%EB%94%A9</link>
            <guid>https://velog.io/@ddo_h/%EC%97%B0%EC%82%B0%EC%9E%90-%EC%98%A4%EB%B2%84%EB%A1%9C%EB%94%A9</guid>
            <pubDate>Sun, 18 Apr 2021 03:07:28 GMT</pubDate>
            <description><![CDATA[<p>이렇게 하면은 원하는대로 sorting할 수 있음</p>
<pre><code>class fishInfo{
public:
    int row, col, size;
    fishInfo(int row, int col, int size): row(row),col(col),size(size){}
    //연산자 오버로딩
    bool operator&lt;(fishInfo f) const{
        if(this-&gt;size == f.size){
            return this-&gt;row &lt; f.row;
        }else{
            return this-&gt;size &lt; f.size;
        }
    }
};

vector&lt;fishInfo&gt; fishes;

sort(fishes.begin(), fishes.end());
for(int i = 0; i &lt; fishes.size(); i++)
        cout &lt;&lt; fishes[i].size &lt;&lt; endl;</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[select 사용 예제]]></title>
            <link>https://velog.io/@ddo_h/select-%EC%82%AC%EC%9A%A9-%EC%98%88%EC%A0%9C</link>
            <guid>https://velog.io/@ddo_h/select-%EC%82%AC%EC%9A%A9-%EC%98%88%EC%A0%9C</guid>
            <pubDate>Tue, 22 Dec 2020 08:29:49 GMT</pubDate>
            <description><![CDATA[<h3 id="select-이용한-쿼리문">select 이용한 쿼리문</h3>
<h4 id="0-기본-개념">0. 기본 개념</h4>
<blockquote>
<p>SELECT는 테이블에서 데이터를 추출할 때 사용하는 것
id: 쿼리문 이름
parameterType: 입력 변수 타입, 예시: map, string, int...
retultType: 출력 변수 타입, 예시: 지정 변수(person), map, string...
SELECT {속성} FROM {테이블이름} WHERE {조건}</p>
</blockquote>
<h4 id="1-사번으로-구성원-검색">1. 사번으로 구성원 검색</h4>
<pre><code>&lt;select id =&quot;getPerson&quot; parameterType=&quot;map&quot; resultType=&quot;com.carrot.model.Person&quot;&gt;
    SELECT * FROM PERSONAL_INFO 
    WHERE _id = #{id} 
&lt;/select&gt;</code></pre><blockquote>
<p>#{id}는 검색하려는 구성원의 사번
=&gt; PERSONAL_INFO(구성원) 중 id(사번)이 일치하는 구성원의 모든 속성값 반환함</p>
</blockquote>
<h4 id="2-이름-혹은-단어로-구성원-검색-concat-사용하기">2. 이름 혹은 단어로 구성원 검색, CONCAT 사용하기</h4>
<pre><code>&lt;select id=&quot;getPeopleList&quot; parameterType=&quot;map&quot; resultType=&quot;com.carrot.model.Person&quot;&gt;
    SELECT * FROM PERSONAL_INFO 
    WHERE name LIKE CONCAT(&#39;%&#39;,#{term},&#39;%&#39;) AND _id != #{uId} 
    ORDER BY department LIMIT 10
&lt;/select&gt;</code></pre><blockquote>
<p> #{term}은 검색어, #{uId}는 현재 사용자의 id
CONCAT은 문자열을 이어주는 함수
=&gt; PERSONAL_INFO(구성원) 중 name(이름)이 검색어를 포함하고 본인은 제외한 리스트의 모든 속성값을 반환함
이때 department(소속)을 기준으로 정렬하며 최대 10개까지 허용함</p>
</blockquote>
<h4 id="3-모든-구성원의-id-반환">3. 모든 구성원의 id 반환</h4>
<pre><code>&lt;select id=&quot;getAllIdList&quot; resultType=&quot;string&quot;&gt;
    SELECT _id FROM PERSONAL_INFO
&lt;/select&gt;</code></pre><blockquote>
<p>조건 없는 select
=&gt; PERSONAL_INFO(구성원)에서 모든 id(사번) 리스트를 반환함</p>
</blockquote>
<h4 id="4-포인트-기록-개수-세기-count-사용하기">4. 포인트 기록 개수 세기, COUNT 사용하기</h4>
<pre><code>&lt;select id=&quot;countHistory&quot; parameterType=&quot;map&quot; resultType=&quot;int&quot;&gt;
    SELECT COUNT(*) FROM POINT_HISTORY
    WHERE point_type = #{type} AND sender_id = #{uId} AND DATE_FORMAT(time_log, &quot;%Y-%m-%d&quot;) = CURDATE(); 
&lt;/select&gt;</code></pre><blockquote>
<p>반환 변수 타입은 int(숫자)형
COUNT는 특정 조건을 만족하는 행의 갯수를 세는 함수
#{type}은 포인트의 종류를 나타냄
DATE_FORMAT은 날짜의 형식을 바꿔주는 함수
DATE_FORMAT(time_log, &quot;%Y-%m-%d&quot;)은 time_log를 &#39;년-월-일&#39;의 형식으로 바꿔줌
CURDATE()는 현재 날짜를 반환하는 함수
=&gt; POINT_HISTORY(포인트 기록)에서 time_log(로그 시간)이 현재 날짜에 해당하고 sender_id(사번)이 사용자의 사번과 일치하며 point_type(포인트 종류)가 일치하는 행의 갯수를 반환함</p>
</blockquote>
<h4 id="5-랭킹-순위-가져오기-sum--join--group-사용하기">5. 랭킹 순위 가져오기, SUM + JOIN + GROUP 사용하기</h4>
<pre><code>&lt;select id=&quot;getRankingList&quot; parameterType=&quot;string&quot; resultType=&quot;map&quot;&gt;
    SELECT PERSONAL_INFO.name, SUM(CARROT_HISTORY.carrot_value) as sum
    FROM CARROT_HISTORY 
    JOIN PERSONAL_INFO ON CARROT_HISTORY.receiver_id = PERSONAL_INFO._id
    WHERE year_month_log = #{yearMonth}
    GROUP BY CARROT_HISTORY.receiver_id
    ORDER BY SUM(carrot_value) DESC, name ASC LIMIT 10
&lt;/select&gt;</code></pre><blockquote>
<p>SUM은 특정 조건에 해당하는 각 리스트의 합을 구해주는 함수
as를 사용하면 쿼리 결과에 보이는 속성의 이름을 재정의할 수 있음
JOIN은 여러 테이블을 하나로 보여줄 때 사용됨
JOIN에는 LEFT, RIGHT, INNER 등 다양한 방식이 있지만, 기본 값은 INNER로 설정되어 있음
INNER JOIN은 공통된 부분만을 보여주며 값이 null인 것은 제외함
예시에서는 PERSONAL_INFO와 CARROT_HISTORY를 JOIN함
GROUP은 원하는 조건에 부합하는 값들을 그룹으로 만들어 보여주는 함수
=&gt; CARROT_HISTORY(당근 내역)에서 name(구성원의 이름), SUM(carrot_value)(당근 합산 결과)를 선택함
이때 당근 내역에서 수신자 사번과 구성원 정보에 있는 사번이 일치하는 조건에서 PERSONAL_INFO를 JOIN함
이때 year_month_log(년월)이 일치해야 하고 receiver_id(수신자 사번)을 기준으로 그룹을 형성하여 receiver_id별 SUM을 구함
SUM은 내림차순, name(이름)은 오름차순으로 정렬하고 최대 10개까지 허용함</p>
</blockquote>
<h4 id="5-포인트-기록-10개씩-불러오기">5. 포인트 기록 10개씩 불러오기</h4>
<pre><code>&lt;select id=&quot;getPointHistory&quot; parameterType=&quot;map&quot; resultType=&quot;map&quot;&gt;
    SELECT point_value as p_val, point_type as p_type, 
    PERSONAL_INFO.name as p_name, DATE_FORMAT(time_log,&#39;%Y-%m-%d %H:%i:%s&#39;) as time_log 
    FROM POINT_HISTORY p
    LEFT JOIN PERSONAL_INFO ON p.receiver_id = PERSONAL_INFO._id
    WHERE sender_id = #{uId}
    ORDER BY time_log DESC LIMIT #{start_index}, #{count}
&lt;/select&gt;</code></pre><blockquote>
<p>FROM(A) LEFT JOIN(B)는 A에 B의 테이블을 붙이는 형식임
A의 값은 모두 나오고 이에 해당하는 B의 값이 없으면 null로 보여줌
#{uId}는 사용자 사번
#{start_index}는 검색 시작할 구간
#{count}는 검색할 개수
=&gt; POINT_HISTORY(포인트 기록)에서 sender_id(전송자 사번)이 사용자 사번이랑 일치하는 것 중에서 point_value(값), point_type(종류), PERSONAL_INFO.name(수신자 이름), time_log(로그 시간)을 반환함
이때, time_log을 내림차순으로 정렬하고 시작점부터 원하는 갯수만큼 반환함
receiver_id(수신자 사번)과 PERSONAL_INFO._id(구성원 테이블의 사번)을 기준으로 POINT_HISTORY에 PERSONAL_INFO(구성원 정보)테이블을 LEFT JOIN 했기 때문에 PERSONAL_INFO.name를 바로 반환할 수 있음</p>
</blockquote>
]]></description>
        </item>
        <item>
            <title><![CDATA[프린터]]></title>
            <link>https://velog.io/@ddo_h/%ED%94%84%EB%A6%B0%ED%84%B0</link>
            <guid>https://velog.io/@ddo_h/%ED%94%84%EB%A6%B0%ED%84%B0</guid>
            <pubDate>Wed, 22 Jul 2020 06:15:46 GMT</pubDate>
            <description><![CDATA[<h4 id="pair-queuepriority_queue-사용">pair queue,priority_queue 사용</h4>
<pre><code>#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;queue&gt;
#include &lt;algorithm&gt;

using namespace std;

int solution(vector&lt;int&gt; priorities, int location) {
    int answer = 0;

    queue&lt;pair&lt;int,int&gt;&gt; nList;
    priority_queue&lt;int&gt; que;
    for(int i = 0; i &lt; priorities.size(); i++){
        nList.push(make_pair(i,priorities[i]));
        que.push(priorities[i]);
    }
    while(!nList.empty()){
        if(nList.front().second == que.top()){
            if(nList.front().first == location)
                return ++answer;
            else{
                ++answer;
                nList.pop();
                que.pop();
            }
        }else{
            nList.push(nList.front());
            nList.pop();
        }

    }
    return answer;
}</code></pre><h4 id="queue는-탐색-기능이-없음">queue는 탐색 기능이 없음</h4>
<pre><code>/*
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;queue&gt;
#include &lt;iostream&gt;

using namespace std;

int solution(vector&lt;int&gt; priorities, int location) {
    int answer = 0;
    queue&lt;int&gt; newList;
    for(int i = 0; i &lt; priorities.size(); i++){
        newList.push(priorities[i]);
    }
    int listsize = newList.size();
    while(1){
        if(newList.empty()) break;
        //가장 앞에 있는 친구 꺼내기
        int curr = newList.front();
        newList.pop();
        //이 친구보다 큰 값이 있는지 찾기
        bool flag = false;//F = 없을 때, T = 있을 때
        if(curr)

        if(flag){//T = 있을 때
        //만약에 있으면 제일 뒤로 보내고 loc 값 변경
        //loc가 0이면 제일 마지막으로 변경
        //loc가 0이 아니면 1 감소
            newList.push(curr);
            if(location == 0) location = newList.size()-1;
            else location--;
        }else{//F = 없을 때
        //없으면 출력하고 answer+1하기
        //loc가 0이면 answer return
        //loc가 0이 아니면 1 감소
            answer++;
            if(location == 0) return answer;
            else location--;
        }
    }
    return answer;
}
*/</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[탑]]></title>
            <link>https://velog.io/@ddo_h/%ED%83%91</link>
            <guid>https://velog.io/@ddo_h/%ED%83%91</guid>
            <pubDate>Tue, 21 Jul 2020 15:53:10 GMT</pubDate>
            <description><![CDATA[<pre><code>#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;iostream&gt;

using namespace std;

vector&lt;int&gt; solution(vector&lt;int&gt; heights) {
    vector&lt;int&gt; answer;
    vector&lt;int&gt; reverse;

    for(int i = heights.size()-1; i &gt;= 0; i--){
        if(i == 0){
            reverse.push_back(0);
            continue;
        }
        int curr = heights[i];
        for(int j = i-1; j &gt;= 0; j--){
            int prev = heights[j];
            if(prev &lt;= curr){
                if(j==0) reverse.push_back(0);
                continue;
            }
            reverse.push_back(j+1);
            break;
        }
    }

    //반환할 때 벡터 다시 거꾸로
    for(int i = reverse.size()-1; i &gt;= 0; i--){
        int temp = reverse[i];
        answer.push_back(temp);
    }

    return answer;
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[다리를 지나는 트럭]]></title>
            <link>https://velog.io/@ddo_h/%EB%8B%A4%EB%A6%AC%EB%A5%BC-%EC%A7%80%EB%82%98%EB%8A%94-%ED%8A%B8%EB%9F%AD</link>
            <guid>https://velog.io/@ddo_h/%EB%8B%A4%EB%A6%AC%EB%A5%BC-%EC%A7%80%EB%82%98%EB%8A%94-%ED%8A%B8%EB%9F%AD</guid>
            <pubDate>Tue, 21 Jul 2020 15:04:49 GMT</pubDate>
            <description><![CDATA[<pre><code>#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;queue&gt;
#include &lt;iostream&gt;

using namespace std;

int solution(int bridge_length, int weight, vector&lt;int&gt; truck_weights) {
    int cnt = 0;
    int sum = 0;
    queue&lt;int&gt; truck_list;
    queue&lt;int&gt; curr;
    for(int i = 0; i &lt; truck_weights.size(); i++)
        truck_list.push(truck_weights[i]);

    for(int i = 0; i &lt; bridge_length; i++)
        curr.push(0);

    do{
        //cout&lt;&lt; cnt &lt;&lt; &quot;: &quot; &lt;&lt; curr.front() &lt;&lt; endl;
        cnt++;
        sum -= curr.front();
        curr.pop();

        if(truck_list.empty()) continue;

        int temp = truck_list.front();
        if(sum+temp &gt; weight){
            curr.push(0);
            continue;
        }

        curr.push(temp);
        sum += temp;
        truck_list.pop();
    }while(!curr.empty());

    return cnt;
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[위장]]></title>
            <link>https://velog.io/@ddo_h/%EC%9C%84%EC%9E%A5</link>
            <guid>https://velog.io/@ddo_h/%EC%9C%84%EC%9E%A5</guid>
            <pubDate>Tue, 21 Jul 2020 13:54:30 GMT</pubDate>
            <description><![CDATA[<p>문제출처: <a href="https://programmers.co.kr/learn/courses/30/lessons/42578?language=cpp">위장 c++</a></p>
<pre><code>#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;map&gt;

using namespace std;

int solution(vector&lt;vector&lt;string&gt;&gt; clothes) {
    int answer = 0;
      int answer = 0;
    map&lt;string,int&gt; list;

    for(int i = 0; i &lt; clothes.size(); i++){
        string temp = clothes[i][1];
        list[temp]++;
    }

    map&lt;string,int&gt;::iterator iter = list.begin();
    answer = iter-&gt;second +1;
    for(iter++; iter != list.end(); iter++){
        answer *= (iter-&gt;second +1);
    }

    return --answer;
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[전화번호 목록]]></title>
            <link>https://velog.io/@ddo_h/%EC%A0%84%ED%99%94%EB%B2%88%ED%98%B8-%EB%AA%A9%EB%A1%9D</link>
            <guid>https://velog.io/@ddo_h/%EC%A0%84%ED%99%94%EB%B2%88%ED%98%B8-%EB%AA%A9%EB%A1%9D</guid>
            <pubDate>Tue, 21 Jul 2020 13:18:48 GMT</pubDate>
            <description><![CDATA[<h4 id="sort-이용해서-쉽게-풀기">sort 이용해서 쉽게 풀기</h4>
<pre><code>#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;

bool solution(vector&lt;string&gt; phone_book) {
    bool answer = true;
    sort(phone_book.begin(), phone_book.end());

    for(int i = 0; i &lt; phone_book.size()-1; i++){
        string curr = phone_book[i];
        string next = phone_book[i+1];
        if(curr == next.substr(0,curr.size())) return false;
    }
    return answer;
}</code></pre><h4 id="해쉬-이용해서-정석대로-풀기">해쉬 이용해서 정석대로 풀기</h4>
<pre><code>#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;unordered_map&gt;

using namespace std;

bool solution(vector&lt;string&gt; phone_book) {
    bool answer = true;
    unordered_map&lt;string,int&gt; hash_map;
    for(int i = 0; i &lt; phone_book.size(); i++)
        hash_map[phone_book[i]] = 1;

    for(int i = 0; i &lt; phone_book.size(); i++){
        string curr = &quot;&quot;;
        for(int j = 0; j &lt; phone_book[i].size(); j++){
            curr += phone_book[i][j];
            if(hash_map[curr] &amp;&amp; curr != phone_book[i]) return false;
        }
    }

    return true;
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[완주하지 못한 선수]]></title>
            <link>https://velog.io/@ddo_h/%EC%99%84%EC%A3%BC%ED%95%98%EC%A7%80-%EB%AA%BB%ED%95%9C-%EC%84%A0%EC%88%98</link>
            <guid>https://velog.io/@ddo_h/%EC%99%84%EC%A3%BC%ED%95%98%EC%A7%80-%EB%AA%BB%ED%95%9C-%EC%84%A0%EC%88%98</guid>
            <pubDate>Tue, 21 Jul 2020 13:02:10 GMT</pubDate>
            <description><![CDATA[<pre><code>#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;


string solution(vector&lt;string&gt; participant, vector&lt;string&gt; completion) {
    string answer = &quot;&quot;;

    sort(participant.begin(), participant.end());
    sort(completion.begin(), completion.end());

    for(int i = 0; i &lt; completion.size(); ){
        string n_part = participant[i];
        string n_comp = completion[i];
        if(n_part == n_comp) i++;
        else return n_part;
    }
    return participant.back();
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[스타트와 링크_14889]]></title>
            <link>https://velog.io/@ddo_h/%EC%8A%A4%ED%83%80%ED%8A%B8%EC%99%80-%EB%A7%81%ED%81%AC14889</link>
            <guid>https://velog.io/@ddo_h/%EC%8A%A4%ED%83%80%ED%8A%B8%EC%99%80-%EB%A7%81%ED%81%AC14889</guid>
            <pubDate>Sun, 31 May 2020 03:21:41 GMT</pubDate>
            <description><![CDATA[<h3 id="문제-출처--스타트와-링크_14889">문제 출처 : <a href="https://www.acmicpc.net/problem/14889">스타트와 링크_14889</a></h3>
<h3 id="파라미터-정리">파라미터 정리</h3>
<p>N 총 사람 수(4 ~ 20, 짝수)
Row 팀(스타트) or Col 팀(링크)로 생각하기
Sij i번 사람과 j번 사람 사이에 존재하는 시너지 (1~100)
Sij는 Sji와 다를 수 있음
Sii는 항상 0 (자기 자신과의 시너지를 의미하므로 0)
각 팀의 능력치는 모든 팀원의 시너지를 더한 것
원하는 것 = 모든 경우의 수에서 두 팀 사이의 능력치 차이의 최솟값을 반환</p>
<h3 id="간략한-과정">간략한 과정</h3>
<p>input_1 N 입력받기
input_2 각 사람들 사이의 능력치 S 입력받기
모든 경우의 수 만들기(방법1 재귀, 방법2 )
각 상황에서 두 팀의 시너지(synergy1, synergy2) 계산하고 차이(sub) 구하기
res = min (res, sub) 비교하기
output 최솟값 res 출력하기</p>
<h3 id="코드">코드</h3>
<blockquote>
<p>재귀 호출 함수를 이용해서 모든 경우의 수 구현</p>
</blockquote>
<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;

using namespace std;

#define INF 9845615

int N;
int Map[20][20];
vector&lt;int&gt; start;
vector&lt;int&gt; link;
int res;

int solve(int cnt){
    if(cnt == N){
        if(start.size() == N/2 &amp;&amp; link.size() == N/2){
            int s_sum = 0, l_sum = 0;
            for(int i = 0; i &lt; N/2; i++){
                for(int j = i+1; j &lt; N/2; j++){
                    if(i == j) continue;
                    int si = start[i], sj = start[j];
                    int li = link[i], lj = link[j];
                    s_sum += Map[si][sj] + Map[sj][si];
                    l_sum += Map[li][lj] + Map[lj][li];
                }
            }
            res = min(res,abs(s_sum-l_sum));
        }
        return res;
    }
    //모든 경우의 수 만들기
    //cnt번 선수를 start에 넣어주거나 link에 넣어주기
    start.push_back(cnt);
    solve(cnt + 1);
    start.pop_back();

    link.push_back(cnt);
    solve(cnt + 1);
    link.pop_back();

    return res;
}

int main()
{
    cin &gt;&gt; N;
    for(int i = 0; i &lt; N; i++)
        for(int j = 0; j &lt; N; j++)
            cin &gt;&gt; Map[i][j];
    res = INF;
    cout &lt;&lt; solve(0) &lt;&lt; endl;

    return 0;
}</code></pre><blockquote>
<p>비트마스킹을 이용해서 구현 (11 00 이면 1은 start 0은 link)</p>
</blockquote>
<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;

#define INF 9845615

int N;
int Map[20][20];
vector&lt;int&gt; start;
vector&lt;int&gt; link;

int calculate(){//두 팀의 시너지 합 계산하기
    int s_sum = 0, l_sum = 0;
    for(int i = 0 ; i &lt; N/2; i++){
        for(int j = i+1; j &lt; N/2; j++){
            if(i == j) continue;
            int si = start[i], sj = start[j];
            int li = link[i], lj = link[j];
            s_sum += Map[si][sj] + Map[sj][si];
            l_sum += Map[li][lj] + Map[lj][li];
        }
    }
    return abs(s_sum-l_sum);
}

int checkBit(int n){
    int res = 0;
    do{
        if(n &amp; 1) res++;
        n = n &gt;&gt; 1;        
    }while(n&gt;0);

    return res;
}

int solve(){
    int res = INF;
    //모든 경우의 수 만들기
    for(int i = 0; i &lt; (1&lt;&lt;N-1); i++){
        //팀이 반반으로 나누어졌을 때
        if(checkBit(i) == (N/2)){
            start.clear();
            link.clear();
            //1은 start팀에 넣고, 0은 link팀에 넣음
            //마지막 수는 항상 link팀에 넣음
            for(int j = 0; j &lt; N-1; j++){
                if(i &amp; (1&lt;&lt;j)) start.push_back(j);
                else    link.push_back(j);
            }link.push_back(N-1);
            //두 팀의 시너지 차이를 구하고 최솟값 고르기
            res = min(res, calculate());
        }
    }

    return res;
}

int main()
{
    cin &gt;&gt; N;
    for(int i = 0; i &lt; N; i++)
        for(int j = 0; j &lt; N; j++)
            cin &gt;&gt; Map[i][j];
    cout &lt;&lt; solve() &lt;&lt; endl;

    return 0;
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[요리사_4012]]></title>
            <link>https://velog.io/@ddo_h/%EC%9A%94%EB%A6%AC%EC%82%AC4012</link>
            <guid>https://velog.io/@ddo_h/%EC%9A%94%EB%A6%AC%EC%82%AC4012</guid>
            <pubDate>Sun, 31 May 2020 03:20:29 GMT</pubDate>
            <description><![CDATA[<h3 id="문제-출처--요리사_4012">문제 출처 : <a href="https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWIeUtVakTMDFAVH">요리사_4012</a></h3>
<p>#스타트와링크 문제랑 똑같음</p>
<h3 id="파라미터-정리">파라미터 정리</h3>
<p>T 테스트 케이스 개수 (1<del>50)
N 음식 개수 (N은 짝수) (4</del>16)
Sij 음식 간 시너지 (1~20000)
i == j 일 경우 시너지가 없음
팀의 총 시너지 = 각 재료 사이의 시너지 모두 더한 것
원하는 것 = 두 팀 사이의 식재료 시너지의 차이가 최소가 될 때 최솟값을 반환</p>
<h3 id="간략한-과정">간략한 과정</h3>
<p>input_1 T 입력받기
input_2_1 N 입력받기
input_2_2 시너지 정보 Arr[16][16] 입력받기
비트 마스크 이용해서 경우의 수 만들기
비트 수가 딱 절반이 되었을 때
0은 A팀 1은 B팀으로 배정한다.
A,B 팀의 총 시너지 차이(sub)을 구한다.
res = min(res, sub)
output &quot;#n&quot; + res 출력하기</p>
<h3 id="코드">코드</h3>
<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;
#include &lt;cstring&gt;

using namespace std;

#define INF 984561542

int T,N;
int Arr[16][16];
vector&lt;int&gt; group_A;
vector&lt;int&gt; group_B;

int calculate(){
    //두 팀의 시너지 각각 계산하고 차이 반환
    int sum_A = 0, sum_B = 0;

    int size = group_A.size();
    for(int i = 0; i &lt; size; i++){
        for(int j = i+1; j &lt; size; j++){
            if(i==j) continue;
            int num1 = group_A[i], num2 = group_A[j];
            sum_A += Arr[num1][num2] + Arr[num2][num1];
        }
    }
    size = group_B.size();
    for(int i = 0; i &lt; size; i++){
        for(int j = i+1; j &lt; size; j++){
            if(i==j) continue;
            int num1 = group_B[i], num2 = group_B[j];
            sum_B += Arr[num1][num2] + Arr[num2][num1];
        }
    }

    return abs(sum_A-sum_B);
}

int checkBit(int n){
    int res = 0;
    do{
        if(n &amp; 1) res++;
        n = n &gt;&gt; 1;
    }while(n&gt;0);
    return res;
}

int solve(){
    int res = INF;
    for(int i = 0; i &lt; (1 &lt;&lt; N-1); i++){
        if(checkBit(i) == N/2){
            group_A.clear();
            group_B.clear();
            for(int j = 0; j &lt; N-1; j++){
                if(i &amp; (1&lt;&lt;j))  group_A.push_back(j);
                else group_B.push_back(j);
            }group_B.push_back(N-1);
            res = min(res,calculate());
        }
    }

    return res;
}

int main()
{
    cin &gt;&gt; T;
    for(int t = 0; t &lt; T; t++){

        cin &gt;&gt; N;
        for(int i = 0; i &lt; N; i++)
            for(int j = 0; j &lt; N; j++)
                cin &gt;&gt; Arr[i][j];

        cout &lt;&lt; &quot;#&quot; &lt;&lt; t+1 &lt;&lt; &quot; &quot; &lt;&lt; solve() &lt;&lt; endl;
    }

    return 0;
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[벽돌깨기_5656]]></title>
            <link>https://velog.io/@ddo_h/%EB%B2%BD%EB%8F%8C%EA%B9%A8%EA%B8%B05656</link>
            <guid>https://velog.io/@ddo_h/%EB%B2%BD%EB%8F%8C%EA%B9%A8%EA%B8%B05656</guid>
            <pubDate>Sun, 31 May 2020 03:17:33 GMT</pubDate>
            <description><![CDATA[<h3 id="문제-출처--벽돌깨기_5656">문제 출처 : <a href="https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRQm6qfL0DFAUo">벽돌깨기_5656</a></h3>
<h3 id="파라미터-정리">파라미터 정리</h3>
<p>N :구슬을 쏠 수 있는 횟수 (1<del>4)
W : col 정보, 가로 (2</del>12)
H : row 정보, 세로 (2<del>15)
HxW 전체 맵 크기, Map[r][c]은 빈 칸(0) 혹은 벽돌(1</del>9)로 구성됨
게임의 규칙{
구슬은 항상 맨 위에 있는 벽돌만 깰 수 있음
(%)벽돌은 본인 위치에서 상하좌우 (벽돌 숫자-1)만큼의 범위를 가짐
범위 내에 있는 벽돌은 동시에 제거됨
연쇄작용으로 인해 구슬은 제거되면서 (%)을 수행함
빈 공간이 발생할 경우 벽돌은 밑으로 떨어짐
}
원하는 것 =  게임 시뮬레이션 후 최대한 많은 벽돌을 제거했을 때 남은 <strong>벽돌의 개수</strong>를 출력</p>
<h3 id="간략한-과정">간략한 과정</h3>
<p>input_1 테스트 케이스 T 입력 받기
input_2_1 N,W,H 입력 받기
input_2_2 초기 맵 정보 Map[15][12]를 입력받음
재귀호출 함수를 이용해서 모든 경우의 수 (= W^N) 구현하기
한 세로줄이 모두 빈칸일 경우 그 곳은 벽돌을 깰 수 없으므로 경우에서 배제
DFS 이용해서 벽돌 숫자에 따라 벽돌이 파괴되고 연쇄작용이 일어나는 것까지 구현
빈 칸이 있을 경우 밑으로 떨어뜨리기
깨트린 벽돌의 최댓값 구하기
res = 처음 - 깨트린 벽돌
output &quot;#n&quot; + res 출력하기</p>
<h3 id="코드">코드</h3>
<pre><code>#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;queue&gt;

using namespace std;

int T;
int N,W,H;
int Map[5][15][12];
int Dr[4] = {0,0,1,-1};
int Dc[4] = {1,-1,0,0};

void drop(int cnt){
    queue&lt;int&gt; Q;
    for(int j = 0; j &lt; W; j++){
        for(int i = H-1; i &gt;= 0; i--){
            if(Map[cnt][i][j]){
                Q.push(Map[cnt][i][j]);
                Map[cnt][i][j] = 0;
            }
        }
        for(int i = H-1; Q.size(); --i, Q.pop())//i &gt; H-1-q.size
            Map[cnt][i][j] = Q.front();
    }
}

int DFS(int r, int c, int cnt){
    int dis = Map[cnt][r][c];////
    int res = 1;
    Map[cnt][r][c] = 0;
    for(int i = 0; i &lt; dis; i++){
        for(int j = 0; j &lt; 4; j++){
            int nr = r + Dr[j]*i;
            int nc = c + Dc[j]*i;
            if(nr &lt; 0 || nc &lt; 0 || nr &gt; H-1 || nc &gt; W-1 || Map[cnt][nr][nc]==0) continue;
            res += DFS(nr,nc,cnt);
        }
    }
    return res;
}

void cpy (int cnt){
    for(int i = 0; i &lt; H; i++)
        for(int j = 0; j &lt; W; j++)
            Map[cnt][i][j] = Map[cnt-1][i][j];
}

int solve(int cnt){
    if(cnt &gt; N) return 0;
    int res = 0;
    for(int i = 0; i &lt; W; i++){
        cpy(cnt);
        int temp = 0;
        bool flag = true;
        for(int j = 0; j &lt; H; j++){
            if(Map[cnt][j][i]==0) continue;
            flag = false;
            temp = DFS(j,i,cnt);
            break;
        }
        if(flag) continue;
        drop(cnt);
        res = max(res, solve(cnt+1)+temp);
    }
    return res;
}

int main()
{
    cin &gt;&gt; T;
    for(int t = 0; t &lt; T; t++){
        cin &gt;&gt; N &gt;&gt; W &gt;&gt; H;
        int sum = 0;
        for(int i = 0; i &lt; H; i++){
            for(int j = 0; j &lt; W; j++){
                cin &gt;&gt; Map[0][i][j];
                sum += Map[0][i][j] ? 1 : 0;
            }
        }
        int res = sum - solve(1);
        cout &lt;&lt; &quot;#&quot; &lt;&lt; t+1 &lt;&lt; &quot; &quot; &lt;&lt; res &lt;&lt; &#39;\n&#39;;
    }

    return 0;
}
</code></pre><h4 id="시행착오">시행착오</h4>
<blockquote>
<p>백업_0604_pm 04:00
dfs 고쳤는데도 오류 발생, 1번 슈팅은 값 잘 나오는데, 2회 이상부터는 null 반환됨</p>
</blockquote>
<pre><code>#include &lt;iostream&gt;
#include &lt;queue&gt;
#include &lt;cstring&gt;
#include &lt;algorithm&gt;

using namespace std;

#define INF 98456154

struct loc{
    int r,c,dis;  
};
int T, N, W, H;
int Map[15][12];
int Bsize[12];
int Dr[4] = {0,1,0,-1};
int Dc[4] = {1,0,-1,0};
int res = INF;


int calculate(){
    int sum = 0;
    for(int i = 0; i &lt; H; i++)
        for(int j = 0; j &lt; W; j++)
            if(Map[i][j] &gt; 0) sum++;

    return sum;
}

void shoot(int pos){
    //맵 삭제 + 빈칸 없애기+Bsize도 반영시켜야 함
    //처음 맞은 곳 0으로 만들고, 큐에 넣음
    queue&lt;loc&gt; myqueue;
    int idx = H-Bsize[pos];
    int dis = Map[idx][pos]-1;
    Map[idx][pos] = 0;
    Bsize[pos]--;
    myqueue.push({idx,pos,dis});

    //연쇄 작용인한 것 처리하기
    do{
        loc curr = myqueue.back();
        myqueue.pop();
        //4방향에 대해서 살펴봄
        for(int i = 0; i &lt; 4; i++){
            int nr = curr.r, nc = curr.c;
            //서비스 범위까지 적용
            for(int j = 0; j &lt; curr.dis; j++){
                nr += Dr[i];
                nc += Dc[i];
                if(Map[nr][nc] == 0) continue;
                int dis = Map[nr][nc]-1;
                Map[nr][nc] = 0;
                Bsize[nc]--;
                if(dis == 0) continue;
                myqueue.push({nr,nc,dis});
            }
        }
    }while(!myqueue.empty());
    //빈칸 생긴 거 없애주기    
    for(int i = 0; i &lt; W; i++){//col
        if(Bsize[i] == 0) continue;
        for(int j = 0; j &lt; Bsize[i]; j++){//블럭 개수
            int lowest = 0;//가장 낮은 빈칸
             for(int k = H-1; k &gt;= 0; k--){//row
                if(Map[k][i] == 0) lowest = max(lowest,k);
                else{
                    if(lowest == 0) continue;
                    else{
                        Map[lowest][i] = Map[k][i];
                        lowest = 0;
                        Map[k][i] = 0;
                        break;
                    }
                }
             }
        }
    }
    return;
}

void solve(int cnt){
    if(cnt&gt;=N){
        res = min(res, calculate());
        return;
    }

    int copy[15][12];
    int copyBsize[12];
    for(int i = 0; i &lt; W; i++){
        if(Bsize[i] &lt;= 0) continue;
        //초기 맵 카피 해두기
        memcpy(copy, Map, sizeof(Map));
        memcpy(copyBsize, Bsize, sizeof(Bsize));
        shoot(i);
        solve(cnt+1);
        //개수 최솟값인지 비교
        //맵 복원
        memcpy(Map, copy, sizeof(Map));
        memcpy(Bsize, copyBsize, sizeof(Bsize));
    }
}

int main()
{
    cin &gt;&gt; T;
    for(int t = 0; t &lt; T; t++){
        cin &gt;&gt; N &gt;&gt; W &gt;&gt; H;
        memset(Map, 0, sizeof(Map));
        memset(Bsize,0,sizeof(Bsize));
        for(int i = 0; i &lt; H; i++){
            for(int j = 0; j &lt; W; j++){
                cin &gt;&gt; Map[i][j];
                if(Map[i][j] &gt; 0) Bsize[j]++;
            }
        }
        solve(0);
        cout &lt;&lt; &quot;#&quot; &lt;&lt; t+1 &lt;&lt; &quot; &quot; &lt;&lt; res &lt;&lt; endl;
    }

    return 0;
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[보물상자 비밀번호_5658]]></title>
            <link>https://velog.io/@ddo_h/%EB%B3%B4%EB%AC%BC%EC%83%81%EC%9E%905658</link>
            <guid>https://velog.io/@ddo_h/%EB%B3%B4%EB%AC%BC%EC%83%81%EC%9E%905658</guid>
            <pubDate>Sun, 31 May 2020 03:15:45 GMT</pubDate>
            <description><![CDATA[<h3 id="문제-출처--보물상자_5658">문제 출처 : <a href="https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRUN9KfZ8DFAUo">보물상자_5658</a></h3>
<h3 id="파라미터-정리">파라미터 정리</h3>
<p>N 입력되는 숫자의 개수 (4의 배수, 8<del>28)
비밀번호를 구성하는 숫자 (0</del>9,A,B,C,D,E,F)
시계 방향으로 돌리면 숫자가 시계방향으로 한 칸씩 회전함
각 변에는 동일한 개수의 숫자 有 시계방향 순으로 높은 자리에 해당함
만들 수 있는 모든 수 중에서 k번째로 큰 수를 10진수로 변환한 것을 비밀번호로 가짐
N개의 숫자가 입력으로 주어질 때 비밀 번호를 출력하라
한 변에 있는 숫자 개수 = N/4;
0번 회전 = (N/4)번 회전</p>
<h3 id="간략한-과정">간략한 과정</h3>
<p>input_1 테스트 케이스 T 입력받기
input_2 N,K 입력받기
input_2 숫자 N개 <strong>공백없이</strong> 입력받기
일단 숫자 N개부터 해체해서 배열에 넣기
0번~(N/4)번 회전하면서 발생하는 수 10진수 수로 변경해서 set에 넣기
sort를 이용해서 set 정렬
output k번째에 해당하는 숫자 반환하기</p>
<h3 id="코드">코드</h3>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;

int T,N,K;
string list[28];
vector&lt;int&gt; myvec;

bool desc(int a, int b){ return a &gt; b; }

int solve(){
    myvec.clear();
    int num = N/4;//3
    string pass = &quot;&quot;;;
    for(int i = 0; i &lt; num; i++){//012
        for(int j = 0; j &lt; N; j++){//0~11
            int idx = (j+(N-1-i))%N;
            pass += list[idx];
            if((j+1)%num != 0) continue;
            int temp = stoi(pass,nullptr,16);
            myvec.push_back(temp);
            pass = &quot;&quot;;
        }
    }
    sort(myvec.begin(), myvec.end(),desc);
    int cnt = 0,tmp = 0;
    for(int i = 0; i &lt; myvec.size(); i++){
        if(myvec[i]==tmp) continue;
        cnt++;
        tmp = myvec[i];
        if(cnt == K) return tmp;
    }

    return -1;
}

int main()
{
    cin &gt;&gt; T;
    for(int t = 0; t &lt; T; t++){
        string temp;
        cin &gt;&gt; N &gt;&gt; K &gt;&gt; temp;
        for(int i = 0; i &lt; N; i++){
            list[i] = temp.substr(i,1);

        }
        cout &lt;&lt; &quot;#&quot; &lt;&lt; t+1 &lt;&lt; &quot; &quot; &lt;&lt; solve() &lt;&lt; endl;
    }

    return 0;
}</code></pre><h3 id="다른-풀이">다른 풀이</h3>
<p>shift를 이용해서 하나씩 이동시키는 방법</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;
#include &lt;vector&gt;

using namespace std;

int T;
int N,K;
int oneSize;
string num[28];

int solve(){
    string numList[7][28];

    for(int i = 0; i &lt; oneSize; i++){
        for(int j = 0; j &lt; N; j++){
            numList[i][j] = num[j];    
        }

        string temp = num[N-1];
        for(int x = N-1; x &gt; 0; x--){
            num[x] = num[x-1];
        }
        num[0] = temp;
    }

    string pw = &quot;&quot;; int cnt = 0;
    vector&lt;int&gt; hexNumList;
    for(int i = 0; i &lt; oneSize; i++){
        for(int j = 0; j &lt; N; j++){
            pw += numList[i][j];
            cnt++;

            if(cnt == oneSize){
                hexNumList.push_back(stoi(pw, nullptr, 16));
                cnt = 0;
                pw = &quot;&quot;;
            }
        }
    }

    sort(hexNumList.begin(), hexNumList.end(),greater&lt;int&gt;());

    int curr = 0; 
    cnt = 0;
    for(int i = 0; i &lt; hexNumList.size(); i++){
        if(curr == hexNumList[i]) continue;
        cnt++;
        curr = hexNumList[i];
        if(cnt == K)
            return hexNumList[i];
    }

    return 0;
}

int main() {
    cin &gt;&gt; T;

    for(int t = 0; t &lt; T; t++){
        string temp = &quot;&quot;;

        cin &gt;&gt; N &gt;&gt; K &gt;&gt; temp;

        oneSize = N/4;

        for(int i = 0; i &lt; N; i++){
            num[i] = temp.substr(i,1);
        }

        cout &lt;&lt; &quot;#&quot; &lt;&lt; t+1 &lt;&lt; &quot; &quot; &lt;&lt; solve() &lt;&lt; endl;
    }

    return 0;
}</code></pre><h3 id="다른풀이">다른풀이</h3>
<p>substr 이용해서 한글자씩 이동</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;

int T;
int N,K;
string hexText;

bool desc(int a, int b){
    return a &gt; b;
}

int solve(){
    int rotSize = N/4;

    vector&lt;int&gt; valList;

    for(int i = 0; i &lt; rotSize; i++){
        string last = hexText.substr(N-1);
        hexText = last + hexText.substr(0,N-1);

        for(int j = 0; j &lt; 4; j++){
            string temp = hexText.substr(0+(j*rotSize),rotSize);
            valList.push_back(stoi(temp, nullptr, 16));
        }
    }

     sort(valList.begin(), valList.end(), desc);

    int cnt = 0, temp = 0;
    for(int k = 0; k &lt; valList.size(); k++){
        if(valList[k] == temp) continue;
        cnt++;
        temp = valList[k];

        if(cnt == K) return temp;
    }

    return 0;
}

int main()
{
    cin &gt;&gt; T;

    for(int t = 0; t &lt; T; t++){
        cin &gt;&gt; N &gt;&gt; K;

        cin &gt;&gt; hexText;

        cout &lt;&lt; &quot;#&quot; &lt;&lt; t+1 &lt;&lt; &quot; &quot; &lt;&lt; solve() &lt;&lt; endl;

    }

    return 0;
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[시험 감독_13458]]></title>
            <link>https://velog.io/@ddo_h/%EC%8B%9C%ED%97%98-%EA%B0%90%EB%8F%8513458</link>
            <guid>https://velog.io/@ddo_h/%EC%8B%9C%ED%97%98-%EA%B0%90%EB%8F%8513458</guid>
            <pubDate>Sun, 31 May 2020 03:14:17 GMT</pubDate>
            <description><![CDATA[<h3 id="문제-출처--시험감독_13458">문제 출처 : <a href="https://www.acmicpc.net/problem/13458">시험감독_13458</a></h3>
<h4 id="문제-후기">문제 후기</h4>
<p>같은 코드라도 iterator를 쓸 때와 그냥 배열처럼 불러올 때 속도 차이가 발생함
iterator 쓸 때 20ms 정도 단축됨</p>
<h3 id="파라미터-정리">파라미터 정리</h3>
<p>N 시험장 개수 (1<del>1,000,000)
Ai i번 시험장에 있는 응시자 수 (1</del>1,000,000)
B 총감독관이 한 시험장에서 감시할 수 있는 응시자의 수 
C 부감독관이 한 시험장에서 감시할 수 있는 응시자의 수 (1~1,000,000)
한 시험장 안에 총감독관은 1명만, 부감독관은 여러명 가능
원하는 것 =  필요한 감독관 수의 최솟값을 반환하기</p>
<h3 id="간략한-과정">간략한 과정</h3>
<p>input_1 N 입력받기
input_2 Ai 응시자수 N번 입력받기
input_3 B,C 입력받기
output 모든 응시생을 감독하기 위해 필요한 감독관의 최소 수를 출력한다.</p>
<h3 id="코드">코드</h3>
<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;

using namespace std;

int N,B,C;
vector&lt;int&gt; people;

long long solve(){
    long long res = 0;
    for(vector&lt;int&gt;::iterator it = people.begin(); it != people.end(); it++){
        int curr = *it;
        curr -= B;
        res ++;
        if(curr &lt;= 0) continue;
        res += curr/C;
        if(curr%C != 0) res++;
    }
    return res;
}

int main()
{
    cin &gt;&gt; N;
    for(int i = 0; i &lt; N; i++){
        int temp;
        cin &gt;&gt; temp;
        people.push_back(temp);
    }
    cin &gt;&gt; B &gt;&gt; C;
    cout &lt;&lt; solve() &lt;&lt; endl;
    return 0;
}</code></pre><h4 id="시행착오">시행착오</h4>
<blockquote>
<p>백업_0531_pm11:40
구현 완료함, 예제는 다 맞는데 제출 시 틀렸다고 나옴
-&gt; 필요한 감독 수가 int 자료형을 넘어간다고 해서 longlong으로 바꿨음
-&gt;그래도 실패라고 나옴 -&gt; 내일 다시 해결
longlong은 cout이 안되는가..? 내일 printf로 도전해봄
-&gt;문제는 총감독관을 빼고난 후 curr값이 음수일 경우 부감독관이 필요없는데 부갑독관을 사용하게 됨 -&gt; 이를 해결해주니깐 해결됨</p>
</blockquote>
]]></description>
        </item>
        <item>
            <title><![CDATA[홈 방범 서비스_2117]]></title>
            <link>https://velog.io/@ddo_h/%ED%99%88-%EB%B0%A9%EB%B2%94-%EC%84%9C%EB%B9%84%EC%8A%A42117</link>
            <guid>https://velog.io/@ddo_h/%ED%99%88-%EB%B0%A9%EB%B2%94-%EC%84%9C%EB%B9%84%EC%8A%A42117</guid>
            <pubDate>Sun, 31 May 2020 03:12:54 GMT</pubDate>
            <description><![CDATA[<h3 id="문제-출처--홈방범서비스_2117">문제 출처 : <a href="https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5V61LqAf8DFAWu">홈방범서비스_2117</a></h3>
<h3 id="파라미터-정리">파라미터 정리</h3>
<p>NxN 전체 맵 크기 (5 ~ 20)
0 : 빈 칸
1 : 집이 있는 위치
방범 서비스는 마름모 모양의 영역에만 제공
K(영역 크기)에 따라 운영 비용 요구됨 (1 ~ K)
K = K x K + (K - 1) x (K - 1), (예: K=1 -&gt; 비용=1, K=2 -&gt; 비용=5, K=3 -&gt; 비용=13)
서비스 영역이 맵 범위를 벗어나더라도 운영 비용은 변경되지 않음
M 각 집이 지불할 수 있는 비용 (1 ~ 10)
회사의 이익 = Mx(서비스 영역 내 집) - 운영비용
원하는 것 = 회사에서 손해를 보지 않으면서 홈방범 서비스를 가장 많은 집들에 제공하는 서비스 영역 찾기
이때 서비스를 제공 받는 집의 수를 출력</p>
<h3 id="간략한-과정">간략한 과정</h3>
<p>input_1 테스트 케이스의 개수 T 입력받기 (1<del>T</del>50)
input_2_1 N,M 입력받기
input_2_2 맵 정보 Map[20][20] 입력받기
(input_2는 T크기 만큼 반복함)
for(int k = 0; k &lt;= N; k++){
//k는 서비스 영역을 의미함, 최대 N사이즈까지 만들 수 있음, 그 이상은 의미 없음
(r,c)는 중간에서 좌상우하 한칸씩 이동하면서 탐색하기
서비스 영역 내 집 개수의 최댓값 구하기
k가 바뀌기 전 회사의 이익을 계산함
회사 이익이 0이상이면 res = max(res, 현재 집 개수) 실행
다음 k로 넘어감
}
output &quot;#n&quot;+ &quot; &quot; + res 출력하기</p>
<h3 id="코드">코드</h3>
<pre><code>#include &lt;iostream&gt;
#include &lt;cstring&gt;
#include &lt;algorithm&gt;
#include &lt;queue&gt;

using namespace std;

int T,N,M;
int Map[20][20];
bool visited[20][20];
int Dr[4] = {0,1,0,-1};
int Dc[4] = {-1,0,1,0};

int solve(){
    int res = 0;
    //모든 영역에 대해서 검사
    for(int i = 0; i &lt; N; i++){
        for(int j = 0; j &lt; N; j++){
            memset(visited, false, sizeof(visited));
            //BFS
            int h_cnt = 0;
            queue&lt;pair&lt;int,int&gt;&gt; myqueue;
            myqueue.push(make_pair(i,j));
            visited[i][j] = true;
            if(Map[i][j] == 1) h_cnt++;
            int size = 1;
            //k 사이즈를 증가시키면서 모든 구간 탐색
            while(!myqueue.empty()){
                if(size &gt; N+1) break;//유의미한 범위를 벗어나면
                int cost = (size * size) + (size - 1)*(size - 1);
                int bene = h_cnt*M;
                //손해x -&gt; 최댓값 비교
                if(cost &lt;= bene) res = max(res,h_cnt);
                int q_size = myqueue.size();
                for(int k = 0; k &lt; q_size; k++){
                    int r = myqueue.front().first;
                    int c = myqueue.front().second;
                    myqueue.pop();

                    for(int t = 0; t &lt; 4; t++){
                        int nr = r + Dr[t];
                        int nc = c + Dc[t];
                        if(nr &lt; 0 || nc &lt; 0 || nr &gt; N-1 || nc &gt; N-1) continue;
                        if(visited[nr][nc]) continue;
                        if(Map[nr][nc] == 1) h_cnt++;
                        visited[nr][nc] = true;
                        myqueue.push(make_pair(nr,nc));
                    }

                }
                size++;
            }
        }
    }

    return res;
}

int main()
{
    cin &gt;&gt; T;
    for(int t = 0; t &lt; T; t++){
        cin &gt;&gt; N &gt;&gt; M;
        for(int i = 0; i &lt; N; i++){
            for(int  j = 0; j &lt; N; j++){
                cin &gt;&gt; Map[i][j];
            }
        }
        cout &lt;&lt; &quot;#&quot; &lt;&lt; t+1 &lt;&lt; &quot; &quot; &lt;&lt; solve() &lt;&lt; endl;
    }

    return 0;
}</code></pre><h4 id="시행착오">시행착오</h4>
<blockquote>
<p>테스트케이스는 통과하지만, 제출 시 시간초과 발생</p>
</blockquote>
<pre><code>#include &lt;iostream&gt;
#include &lt;cstring&gt;
#include &lt;algorithm&gt;
#include &lt;queue&gt;

using namespace std;

struct loc{
    int r,c,d;  
};

int N,M,T;
int map[50][50] = {0};

int dR[4] = {0,1,0,-1};
int dC[4] = {1,0,-1,0};

int solve(){
    int res = 0;

    for(int d = 0; d &lt;= N; d++){
        for(int i = 0; i &lt; N; i++){
            for(int j = 0; j &lt; N; j++){

                int cost = d*d + (d+1)*(d+1);
                int cnt = 0;
                bool visit[50][50] = {false,};

                queue&lt;loc&gt; list;
                list.push({i,j,0});

                do{
                    loc curr = list.front();
                    list.pop();

                    visit[curr.r][curr.c] = true;

                    if(map[curr.r][curr.c] == 1) cnt++;
                    if(curr.d &gt;= d) continue;

                    for(int n = 0; n &lt; 4; n++){
                        int nr = curr.r + dR[n];
                        int nc = curr.c + dC[n];

                        if(nr &lt; 0 || nc &lt; 0 || nr &gt; N-1 || nc &gt; N-1) continue;
                        if(visit[nr][nc]) continue;

                        list.push({nr,nc,curr.d+1});
                        visit[nr][nc] = true;
                    }
                }while(!list.empty());

                if(cost &lt;= cnt*M) res = max(res, cnt);
            }
        }
    }


    return res;
}


int main() {

    cin &gt;&gt; T;    

    for(int t = 0; t &lt; T; t++){

        cin &gt;&gt; N &gt;&gt; M;

        memset(map,0,sizeof(map));
        for(int i = 0; i &lt; N; i++){
            for(int j = 0; j &lt; N; j++){
                cin &gt;&gt; map[i][j];
            }
        }

        cout &lt;&lt; &quot;#&quot; &lt;&lt; t+1 &lt;&lt; &quot; &quot; &lt;&lt; solve() &lt;&lt; endl;
    }


    return 0;
}</code></pre><blockquote>
<p>T = 1인 예제
1
8 3
0 0 0 0 0 1 0 0
0 1 0 1 0 0 0 1
0 0 0 0 0 0 0 0
0 0 0 1 0 1 0 0
0 0 1 1 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 1 0 1 0
1 0 0 0 0 0 0 0</p>
</blockquote>
]]></description>
        </item>
        <item>
            <title><![CDATA[퇴사_14501]]></title>
            <link>https://velog.io/@ddo_h/%ED%87%B4%EC%82%AC14501</link>
            <guid>https://velog.io/@ddo_h/%ED%87%B4%EC%82%AC14501</guid>
            <pubDate>Sun, 31 May 2020 03:10:05 GMT</pubDate>
            <description><![CDATA[<h3 id="문제-출처--퇴사_14501">문제 출처 : <a href="https://www.acmicpc.net/problem/14501">퇴사_14501</a></h3>
<h3 id="dp-문제-풀이">DP 문제 풀이</h3>
<p>DP 문제는 구현은 쉬운데, 조건문이 까다로움
여러 가지 상황을 생각해서 빈틈이 생기지 않도록 조건문을 짜야할 것 같음
구현 시작 전에 예제를 손으로 풀어보고 특별한 경우가 있는 지 확인하기</p>
<h3 id="파라미터-정리">파라미터 정리</h3>
<p>N 남은 기간, 퇴사는 N+1일 째 되는 날 함 (1<del>15)
Ti 상담을 완료하는 데 걸리는 시간 (1</del>5)
Pi 상담 후 받는 금액 (1~100)
상담을 완료하는 기간 Ti 동안은 다른 일을 중복으로 할 수 없음
원하는 것 = 일정이 주어졌을 때 최대 수익을 반환하기</p>
<h3 id="간략한-과정">간략한 과정</h3>
<p>input_1 N 입력받기
input_2 [Ti Pi]를 N번 입력 받는다. 각 순서는 1일부터 N일 까지를 의미함
Ti는 period[15], Pi는 money[15]에 순차적으로 넣음
누적되는 금액을 나타내는 sum[16]을 만듦
각 상황에서 전월 ~ n월 전에 대한 금액과 현재 금액을 선택했을 때 득실을 고려함
상황마다 최댓값이 되도록 갱신함
output 최종적으로 가장 큰 값인 sum[15]를 출력함</p>
<h3 id="코드">코드</h3>
<h4 id="for문-정방향">for문 정방향</h4>
<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;

int N;
vector&lt;int&gt; period, money;

int solve(){
    int res = 0;
    int sum[15] = {0};
    //거꾸로 돌아가야 함
    for(int i = 0; i &lt; N; i++){
        int np = period.back();
        period.pop_back();
        int nm = money.back();
        money.pop_back();
        int idx = N-1 -i;
        if(idx+np &gt; N) {
            if(i == 0) continue;
            sum[i] = sum[i-1];
            //cout &lt;&lt; i &lt;&lt; &quot; : &quot; &lt;&lt; sum[i] &lt;&lt; endl;
            continue;
        }
        //if(np)
        idx = i-(np);
        int curr;
        if(idx &lt; 0) curr = nm;
        else curr = sum[i-np] + nm;

        sum[i] = max(sum[i-1], curr);
        cout &lt;&lt; i &lt;&lt; &quot; : &quot; &lt;&lt; sum[i] &lt;&lt; endl;
    }
    res = sum[N-1];
    return res;
}

int main()
{
    cin &gt;&gt; N;
    for(int i = 0; i &lt; N; i++){
        int p1, m1;
        cin &gt;&gt; p1 &gt;&gt; m1;
        period.push_back(p1);
        money.push_back(m1);
    }
    cout &lt;&lt; solve() &lt;&lt; endl;

    return 0;
}
</code></pre><h4 id="for문-역방향">for문 역방향</h4>
<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;

int N;
vector&lt;int&gt; Time;
vector&lt;int&gt; Price;

int solve(){
    int sum[16] = {0};
    int size = Time.size();
    for(int i = size-1; i &gt;= 0; i--){
        int date = Time.back();
        Time.pop_back();
        int cost = Price.back();
        Price.pop_back();
        if(date+i &lt;= N){
            int temp = sum[i+date]+cost;
            sum[i] = max(temp,sum[i+1]);
        }else{
            sum[i] = sum[i+1];
        }
    }

    return sum[0];
}

int main()
{
    cin &gt;&gt; N;
    for(int i = 0; i &lt; N; i++){
        int t,p;
        cin &gt;&gt; t &gt;&gt; p;
        Time.push_back(t);
        Price.push_back(p);
    }
    cout &lt;&lt; solve() &lt;&lt; endl;

    return 0;
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[수영장_1952]]></title>
            <link>https://velog.io/@ddo_h/%EC%88%98%EC%98%81%EC%9E%A51952</link>
            <guid>https://velog.io/@ddo_h/%EC%88%98%EC%98%81%EC%9E%A51952</guid>
            <pubDate>Sun, 31 May 2020 03:06:36 GMT</pubDate>
            <description><![CDATA[<h3 id="문제-출처--수영장_1952">문제 출처 : <a href="https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PpFQaAQMDFAUq">수영장_1952</a></h3>
<h3 id="파라미터-정리">파라미터 정리</h3>
<p>T 테스트 케이스 개수
이용권 종류 : 
1일 이용권-1일 이용 가능
1달 이용권-1달 동안 이용 가능, 매달 1일부터 시작
3달 이용권-연속된 3달 동안 이용 가능, 매달 1일부터 시작, 해가 바뀌면 사라짐
1년 이용권-1년 동안 이용 가능, 매년 1월 1일부터 시작
원하는 것 = 각 이용권의 요금과 각 달의 이용 계획이 주어질 때, 가장 적은 비용으로 수영장을 이용할 수 있는 방법을 찾고 비용을 출력하기</p>
<h3 id="간략한-과정">간략한 과정</h3>
<p>input_1 T 입력받기
input_2 {각 이용권의 가격 4개,
        각 달 마다 이용 계획 12달} x T만큼 입력받기
DP를 이용한 알고리즘을 테스트 케이스만큼 실행함{
각 달마다 1일 이용권으로 결제했을 때 소요되는 금액 계산
모든 달에 대해 1달 이용권,1일 이용권 총 요금 중 최솟값 비교
123,234,345,456,567,678,789,8910,91011,101112,1112,12 을 선택했을 때 발생하는 금액과 현재 최솟값 비교
현재 계산된 총 요금과 1년 이용권 금액 최솟값 비교
테스트 케이스 숫자와 최솟값 출력
}
output &quot;#n&quot; + &quot;각 케이스마다 비용을 가장 적게 지출하는 비용&quot;  반환하기</p>
<h3 id="코드">코드</h3>
<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;

#define INF 9845651

struct cost{
  int n1,n2,n3,n4;  
};
int T;
vector&lt;cost&gt; ticket;
int sched[50][12];

void solve(){
    int cnt = 0;

    do{
        int res = INF;
        int sum[13] = {0};
        //각 케이스의 요금권
        cost n_cost = ticket[cnt];
        //각각의 경우 실행하고 최솟값 갱신
        //1일권 만 사용했을 때 vs. 1달권이랑 비교
        int n_mon[12];
        for(int i = 0; i &lt; 12; i++){
            int mon = sched[cnt][i];
            n_mon[i] = min(n_cost.n1*mon, n_cost.n2);
        }
        //3달 마다 이전값이랑 비교
        for(int  i = 1; i &lt; 13; i++){
            sum[i] = sum[i-1] + n_mon[i-1];
            if(i-3 &gt;= 0)
                sum[i] = min(sum[i], sum[i-3] + n_cost.n3);
        }
        //1년 이용권이랑 비교
        res = min(n_cost.n4, sum[12]);
        //최솟값 출력
        cout &lt;&lt; &quot;#&quot; &lt;&lt; cnt+1 &lt;&lt; &quot; &quot; &lt;&lt; res &lt;&lt; endl;
        //다음 케이스로 넘어감
        cnt++;
    }while(cnt!=T);


    return;
}

int main()
{
    cin &gt;&gt; T;
    for(int i = 0; i &lt; T; i++){
        int x,y,z,a;
        cin &gt;&gt; x &gt;&gt; y &gt;&gt; z &gt;&gt; a;
        ticket.push_back({x,y,z,a});
        for(int k = 0; k &lt; 12; k++)
            cin &gt;&gt; sched[i][k];
    }
    solve();

    return 0;
}</code></pre><h4 id="시행착오">시행착오</h4>
<blockquote>
<p>T= 1, 예제
1
10 40 100 300
0 0 2 9 1 5 0 0 0 0 0 0</p>
</blockquote>
<p><img src="https://images.velog.io/images/ddo_h/post/b57826ae-6389-4f1f-b2c7-c7de11aa0007/%EC%BA%A1%EC%B2%98.PNG" alt=""></p>
<blockquote>
<p>백업_0531_pm2:30
구현 완료, T =1인 예제 통과함
SWEA 제출 결과 FAIL 나옴
문제점 : 3달 이용권을 한번만 선택해서 문제가 발생함
3달 이용권을 여러 달 선택할 수 있게 바꾸기</p>
</blockquote>
<pre><code>        //3달 마다 이전값이랑 비교
        int sub_sum = INF;
        for(int k = 0; k &lt; 12; k++){
            int temp = 0;
            if(k == 10){
                temp = n_mon[k] + n_mon[k+1];
            }else if(k == 11){
                temp = n_mon[k];
            }else
                temp = n_mon[k] + n_mon[k+1] + n_mon[k+2];    
           temp = sum - temp + n_cost.n3;
           if(temp &lt; sum) sub_sum = min(sub_sum, temp);
        }
        sum = min(sub_sum, sum);</code></pre>]]></description>
        </item>
    </channel>
</rss>