Difference between r1.1 and the current
@@ -5,6 +5,8 @@
= 참가자 =
* 15이원준
* 박인서
== 15이원준 ==
{{{
@@ -35,12 +37,45 @@
}
}}}
== 박인서 ==
== 곽정흠 ==
= 아이디어 =
== 15이원준 ==
* 미리 세개로 만들 수 있는 수를 구해둔 다음 input값의 결과로 출력했습니다.
== 박인서 ==
== 곽정흠 ==
}}}
== 박인서 ==
{{{
#include <iostream>
int a[50] = { 0, };
int check(int n) {
for (int i = 1; a[i] <= n; i++) {
for (int j = i; a[j] <= n - a[i]; j++) {
for (int k = j; a[k] <= n - a[i] - a[j]; k++) {
if (a[i] + a[j] + a[k] == n) return 1;
}
}
}
return 0;
}
int main()
{
int t;
for (int i = 0, j = 0; j < 1000; i++, j += i)
a[i] = j;
std::cin >> t;
while (t--) {
int n;
std::cin >> n;
std::cout << check(n) << std::endl;
}
return 0;
}
}}}
== 곽정흠 ==
= 아이디어 =
== 15이원준 ==
* 미리 세개로 만들 수 있는 수를 구해둔 다음 input값의 결과로 출력했습니다.
* 1000까지의 삼각 수들을 구한 뒤 입력 값에 따라 3중 for문을 돌려가며 확인한다.
== 곽정흠 ==
3.1. 15이원준 ¶
#include<iostream>
using namespace std;
int main(){
int arr[46];
int dp[1001] = { 0, };
for(int i = 1; i<45; i++){
arr[i] = (i*(i+1))/2;
}
for(int i = 1; i<45; i++){
for(int j = 1; j<45 && arr[i] + arr[j] <= 1000; j++){
for(int k = 1;arr[i] + arr[j] + arr[k] <=1000 && k<45; k++){
dp[arr[i] + arr[j] + arr[k]] = 1;
}
}
}
int N;
cin>> N;
for(int i = 0; i<N; i++){
int tmp;
cin>> tmp;
cout<< dp[tmp] <<endl;
}
}
3.2. 박인서 ¶
#include <iostream>
int a[50] = { 0, };
int check(int n) {
for (int i = 1; a[i] <= n; i++) {
for (int j = i; a[j] <= n - a[i]; j++) {
for (int k = j; a[k] <= n - a[i] - a[j]; k++) {
if (a[i] + a[j] + a[k] == n) return 1;
}
}
}
return 0;
}
int main()
{
int t;
for (int i = 0, j = 0; j < 1000; i++, j += i)
a[i] = j;
std::cin >> t;
while (t--) {
int n;
std::cin >> n;
std::cout << check(n) << std::endl;
}
return 0;
}










