해커랭크(HackerRank)
Utopian Tree
cepiloth
2018. 8. 19. 17:30
반응형
1. 문제
봄에는 2배로 커지고 여름에는 1씩 증가 된다.
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 | #include <bits/stdc++.h> using namespace std; int utopianTree(int n) { // Complete this function int sol = 1; for(int i =1; i<=n; i++) { if(i & 1) { sol = sol * 2; } else { sol = sol + 1; } } return sol; } int main() { int t; cin >> t; for(int a0 = 0; a0 < t; a0++){ int n; cin >> n; int result = utopianTree(n); cout << result << endl; } return 0; } | cs |
반응형