Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 누적 합
- 그래프
- 정렬
- 그리디 알고리즘
- 다익스트라
- 다이나믹 프로그래밍
- 자료구조
- 구현
- 유니티
- 우선순위 큐
- 문자열
- 백준
- DFS
- c++
- Unreal Engine 5
- 투 포인터
- ue5
- BFS
- 유니온 파인드
- VR
- 시뮬레이션
- 재귀
- 스택
- 수학
- 브루트포스
- 백트래킹
- 알고리즘
- XR Interaction Toolkit
- 트리
- Team Fortress 2
Archives
- Today
- Total
1일1알
백준 9009번 피보나치 C++ 본문
1,000,000,000 까지 포함할 수 있는 피보나치 배열을 만들고, 큰 값부터 빼가면서 답을 구했다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
vector<int> fib(47);
fib[0] = 0;
fib[1] = 1;
for (int i = 2; i < 47; i++) {
fib[i] = fib[i - 1] + fib[i - 2];
}
while (t--) {
vector<int> ans;
int num;
cin >> num;
for (int i = 46; i >= 1; i--) {
if (num < fib[i]) continue;
ans.push_back(fib[i]);
num -= fib[i];
}
for (int i = ans.size() - 1; i >= 0; i--) {
cout << ans[i] << " ";
}
cout << "\n";
}
};
'알고리즘' 카테고리의 다른 글
백준 16987번 계란으로 계란치기 C++ (0) | 2021.12.23 |
---|---|
백준 10835번 카드게임 C++ (0) | 2021.12.22 |
백준 15661번 링크와 스타트 C++ (0) | 2021.12.20 |
백준 3079번 입국심사 C++ (0) | 2021.12.19 |
백준 15486 퇴사 2 C++ (0) | 2021.12.18 |