1 min read

10448 유레카 이론

Tn = 1 + 2 + 3 + … + n = n(n+1)/2 이고

이 T의 3가지의 합으로 해당 숫자가 이 합에 들어가는가 안들어가는가를 물어보는 문제이다.

속도를 빠르게하기위해 T를 전부 구한다음 반복문을 이용해서 가능한 조합인 경우 체크표시를 해준다.

풀이는 다음과 같다.

 

 

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
#include<iostream>
#include <algorithm>
#include <vector>
using namespace std;
int  m;
int count = 0;
std::vector<int> arr;
std::vector<int> t;
int vit[10000];
void ispasssibal() {
    for (auto &i : t) {
        for (auto &j : t) {
            for (auto &k : t) {
                vit[i + j + k] = true;
            }
        }
    }
}
int main() {
    std::cin >> m;
    arr.resize(m);
    for (auto &i : arr) {
        cin >> i;
    }
    int maxVal = *std::max_element(arr.begin(), arr.end());
    for (int i = 1; i < maxVal; ++i) {
        int val = (i * (i + 1) )/ 2;
        if (val < maxVal)
            t.push_back(val);
    }
    ispasssibal();
    for (auto &val : arr) {
        if (vit[val] == true)
            std::cout << “1” << std::endl;
        else
            std::cout << “0” << std::endl;
    }
}
cs