티스토리 뷰
https://www.acmicpc.net/problem/1041
1041번: 주사위
첫째 줄에 N이 주어진다. 둘째 줄에 주사위에 쓰여 있는 수가 주어진다. 위의 그림에서 A, B, C, D, E, F에 쓰여 있는 수가 차례대로 주어진다. N은 1,000,000보다 작거나 같은 자연수이고, 쓰여 있는 수�
www.acmicpc.net
백준 소스코드 [C++] 1041 주사위
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,sum=0,m;
cin >> n;
vector <int> dice;
for (int i = 0;i < 6;i++) {
cin >> m;
dice.push_back(m);
sum += m;
}
long long first = *min_element(dice.begin(), dice.end());
int arr[12] = { dice[0] + dice[1],
dice[0] + dice[2],
dice[0] + dice[3],
dice[0] + dice[4],
dice[1] + dice[2],
dice[1] + dice[3],
dice[1] + dice[5],
dice[2] + dice[4],
dice[2] + dice[5],
dice[3] + dice[4],
dice[3] + dice[5],
dice[4] + dice[5]
};
long long second = *min_element(arr, arr + 12);
int arrr[8] = { dice[0] + dice[1] + dice[2],
dice[0] + dice[1] + dice[3],
dice[0] + dice[2] + dice[4],
dice[0] + dice[3] + dice[4],
dice[1] + dice[2] + dice[5],
dice[1] + dice[3] + dice[5],
dice[2] + dice[4] + dice[5],
dice[3] + dice[4] + dice[5]
};
long long third = *min_element(arrr, arrr + 8);
if (n == 1) cout << sum - *max_element(dice.begin(), dice.end());
else cout << (second * 4 + first * 4 * (n - 2)) * (n - 1) + first*(n - 2)*(n - 2) + second * 4 * (n - 2) + third * 4;
return 0;
}
'백준' 카테고리의 다른 글
백준 소스코드 [C++] 1992 쿼드트리 (0) | 2020.08.17 |
---|---|
백준 소스코드 [C++] 1991 트리 순회 (0) | 2020.08.17 |
백준 소스코드 [C++] 1918 후위 표기식 (0) | 2020.08.17 |
백준 소스코드 [C++] 1725 히스토그램 (0) | 2020.08.17 |
백준 소스코드 [C++] 6549 히스토그램에서 가장 큰 직사각형 (0) | 2020.08.17 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- MeTal
- WWDC21
- 벨만포드 시간복잡도
- State Restoration
- rxswift
- 최단경로 문제
- 강한 순환 참조
- 벨만포드 알고리즘
- test coverage
- mach-o
- CPU와 Memory
- IOS
- CompositionalLayout
- WWDC19
- 최단경로 알고리즘
- HIG
- WWDC17
- 최단경로문제
- Testable
- 컴퓨터 추상화
- observeOn
- 다익스트라 시간복잡도
- 네트워크 플로우
- 부스트캠프 6기
- 네트워크 유량
- 에드몬드 카프 알고리즘
- WWDC16
- 코딩대회
- 최대 매칭
- 포드 풀커슨 알고리즘
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함