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 | 29 | 30 | 31 |
Tags
- Stack
- 북리뷰
- 코테
- 정석학술정보관
- 오에스
- 코딩
- 스택
- 백준
- 알고리즘
- 컴퓨터공학과
- bfs
- coding
- OS
- cs
- 브루트포스
- 그래프
- 문제풀이
- 컴공
- 자료구조
- 구현
- 개발
- 오퍼레이팅시스템
- DP
- 컴공과
- c++
- Computer science
- 정석
- Operating System
- 너비우선탐색
- vector
Archives
- Today
- Total
Little Jay
[C++] 백준 2018번 - 수들의 합 5 본문
1, 2가 입력되었을때를 생각안했다가 틀렸던 문제
base case에 대해서도 항상 생각하자
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int n;
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
int left = 1;
int right = 2;
int total = 1;
int ans = 0;
if (n == 1 || n == 2) {
cout << 1 << endl;
return 0;
}
while (left <= n) {
total += right;
if (total == n) {
ans++;
total = 0;
left++;
right = left;
}
else if (total > n) {
left++;
total = 0;
right = left;
}
else right++;
}
cout << ans << endl;
return 0;
}
'알고리즘 > BOJ' 카테고리의 다른 글
[C++] 백준 11404번 - 플로이드 (0) | 2022.06.04 |
---|---|
[C++] 백준 4358번 - 생태학 (0) | 2022.06.02 |
[C++] 백준 12813번 - 이진수연산 (0) | 2022.05.22 |
[C++] 백준 10282번 - 해킹 (0) | 2022.05.13 |
[C++] 백준 1753번 - 최단 경로 (0) | 2022.05.13 |
Comments