728x90
- 문제
https://www.acmicpc.net/problem/1292
1292번: 쉽게 푸는 문제
첫째 줄에 구간의 시작과 끝을 나타내는 정수 A, B(1 ≤ A ≤ B ≤ 1,000)가 주어진다. 즉, 수열에서 A번째 숫자부터 B번째 숫자까지 합을 구하면 된다.
www.acmicpc.net
- 풀이법
제한 시간이 2초이기 때문에 이중 for 문을 통해 구현했다.
- 풀이 - C++
#include <iostream>
#include <vector>
using namespace std;
vector <int> v(1000);
int a, b, ans, t;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> a >> b;
for(int i = 1; i <= 1000; i++) {
for(int j = 0; j < i && idx < 1000; j++) v[t++] = i;
}
for(int i = a - 1; i < b; i++) ans += v[i];
cout << ans;
return 0;
}
728x90
'PS > 백준' 카테고리의 다른 글
[ 백준 ] 24416번 : 알고리즘 수업 - 피보나치 수 1 - (CPP/C/C++) (0) | 2022.06.06 |
---|---|
[ 백준 ] 1021번 : 회전하는 큐 - (CPP/C/C++) (0) | 2022.06.06 |
[ 백준 ] 14425번 : 문자열 집합 - (CPP/C/C++) (0) | 2022.05.09 |
[ 백준 ] 2557번 : Hello World - (C++/C/CPP , JAVA/자바, PYTHON/파이썬) (0) | 2022.05.09 |
[ 백준 ] 21758번 : 꿀따기 - (C/CPP/C++) (0) | 2022.05.09 |