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
- 다이나믹 프로그래밍
- BFS
- 브루트포스
- 유니온 파인드
- 그래프
- 투 포인터
- c++
- Team Fortress 2
- XR Interaction Toolkit
- 문자열
- 그리디 알고리즘
- 누적 합
- 우선순위 큐
- ue5
- 시뮬레이션
- 백준
- DFS
- 트리
- 구현
- 재귀
- 알고리즘
- Unreal Engine 5
- 스택
- 자료구조
- 다익스트라
- 수학
- 정렬
- VR
- 백트래킹
- 유니티
Archives
- Today
- Total
1일1알
백준 1292번 쉽게 푸는 문제 C++ 본문
누적 합을 저장하는 벡터를 만들어서 문제를 해결하였다.
#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>
#include <iomanip>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vector<int> sum(1001, 0);
int num = 1;
int cnt = 0;
for (int i = 1; i <= 1000; i++) {
sum[i] = sum[i - 1] + num;
cnt++;
if (cnt == num) {
num++;
cnt = 0;
}
}
int left, right;
cin >> left >> right;
int ans = sum[right] - sum[left - 1];
cout << ans;
};
'알고리즘' 카테고리의 다른 글
백준 1337번 올바른 배열 C++ (0) | 2022.04.23 |
---|---|
백준 1331번 나이트 투어 C++ (0) | 2022.04.22 |
백준 1283번 단축키 지정 C++ (0) | 2022.04.20 |
백준 1270번 전쟁-땅따먹기 C++ (0) | 2022.04.19 |
백준 1251번 단어 나누기 C++ (0) | 2022.04.18 |