알고리즘 문제/BOJ
2309번 일곱 난쟁이
parkit
2018. 8. 23. 09:32
728x90
반응형
브루트 포스 문제이다.
일곱 난쟁이들의 키의 합이 100이므로,
(9명 전체 키의 합) - (일곱 난쟁이가 아닌 사람 1) - (일곱 난쟁이가 아닌 사람 2)의 값이 100이 나오면 된다.
그리고, 구했을 때는 stop으로 for문을 멈춘다.
https://www.acmicpc.net/problem/2309
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 57 58 59 60 61 62 | #include <iostream> #include <queue> #include <cstdio> #include <vector> #include <cstring> #include <string> #include <math.h> #include <algorithm> using namespace std; int height[9] = { 0, }; vector<int> v; int main(void) { int sum_height = 0; int r = 0, c = 0; for (int i = 0; i < 9; i++) { scanf("%d", &height[i]); sum_height += height[i]; } bool stop = false; for (int i = 0; i < 8 && !stop; i++) { for (int j = i + 1; j < 9 && !stop; j++) { if ((sum_height - height[i] - height[j]) == 100) { stop = true; r = i; c = j; } } } for (int i = 0; i < 9; i++) { if (i != r && i != c) { v.push_back(height[i]); } } sort(v.begin(), v.end()); int len = v.size(); for (int i = 0; i < len; i++) { printf("%d\n", v[i]); } return 0; } | cs |
728x90
반응형