알고리즘/BOJ

백준 10819번 차이를 최대로

꾸준함. 2019. 1. 19. 17:22

문제 링크입니다: https://www.acmicpc.net/problem/10819


next_permutation을 이용하여 쉽게 풀 수 있는 문제였습니다.


#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;

 

int main(void)

{

        ios_base::sync_with_stdio(0);

        cin.tie(0);

        int N;

        cin >> N;

 

        vector<int> v(N);

        for (int i = 0; i < N; i++)

                 cin >> v[i];

 

        int result = 0;

        sort(v.begin(), v.end());

        do

        {

                 int temp = 0;

                 for (int i = 0; i < v.size() - 1; i++)

                         temp += abs(v[i] - v[i + 1]);

 

                 result = max(result, temp);

        } while (next_permutation(v.begin(), v.end()));

 

        cout << result << "\n";

        return 0;

}


개발환경:Visual Studio 2017

지적, 조언, 질문 환영입니다! 댓글 남겨주세요~

반응형

'알고리즘 > BOJ' 카테고리의 다른 글

백준 1525번 퍼즐  (0) 2019.01.20
백준 10971번 외판원 순회 2  (2) 2019.01.19
백준 15684번 사다리 조작  (4) 2019.01.18
백준 1213번 팰린드롬 만들기  (0) 2019.01.18
백준 10827번 a^b  (0) 2019.01.18