구현(Implementation)
백준 1233번: 주사위
cepiloth
2018. 7. 19. 19:02
반응형
https://www.acmicpc.net/problem/1233
1. 문제
지민이는 주사위 던지기 게임을 좋아하여 어느 날 옆에 있는 동호를 설득하여 주사위 던지기 게임을 하자고 하였다. 총 3개의 주사위가 있다. 그리고 이 주사위는 각각 S1(2 ≤ S1 ≤ 20), S2(2 ≤ S2 ≤ 20), S3(2 ≤ S3 ≤ 40)개의 면이 있다. (실제로는 주사위가 6개의 면이 있는 것이 정상이지만 특별한 주사위라 생각하자.)
문제는 세 개의 주사위를 동시에 던졌을 때 가장 높은 빈도로 나오는 세 주사위의 합을 구하는 것이다.
2. 알고리즘
키워드 - 구현, 배열
3. 코드
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #include <iostream> #include <sstream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <list> #include <queue> #include <deque> #include <map> #include <set> #include <stack> #include <cstring> #include <math.h> using namespace std; #define MAX_SIZE 100 #define INF 0x7fffffff #define CENDL "\n" #define ll long long int table[81]; int main() { cin.tie(0); std::ios::sync_with_stdio(false); int a, b, c; cin >> a >> b >> c; // 주사위의 면 마다의 모든 합계를 구한다. for(int i=1; i<=a; i++) { for(int j=1; j<=b; j++){ for (int k=1; k<=c; k++) { // i + j + k 합은 세개의 주사위의 합이 된다. table[i+j+k]++; } } } int max = 0; int index = 0; // table 에는 세개의 주사위의 총합의 경우의 수가 적산 된다. for(int i=0; i<81; i++) { if (max < table[i]) { max = table[i]; index = i; } } cout << index << CENDL; return 0; } | cs |
반응형