본문 바로가기

백준

1024 수열의 합

https://danco.tistory.com/30

 

[1024] 수열의 합

https://www.acmicpc.net/problem/1024 처음에 나누는 수 L을 짝수일 때, 홀수일 때로 나눠서 나온 수를 수열의 가운데 있는 숫자라고 정하고, 그 수 앞뒤로 연속되는 숫자를 출력하는 방식으로 했는데 94%에

danco.tistory.com

 

어려웠다! 어떻게 풀지 감이 안 잡혀서 결국 다른사람 블로그를 보고 풀었다. 

 

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <bitset>
#include <stdio.h>
#include <math.h>
#include <sstream>

#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()

using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using iis = pair<int, string>;
using ii64 = pair<i64, i64>;
using iii = tuple<int, int, int>;

int main() {
    int n, l;
    scanf("%d %d", &n, &l);
    
    for (int i = l; i <= 100; i++) {
        int t = (i - 1) * i / 2;
        if ((n - t) % i != 0 || (n - t) / i < 0)
            continue;
        
        for (int j = 0; j < i; j++)
            printf("%d ", (n - t) / i + j);
        return 0;
    } 
    
    printf("-1");
    
    
    return 0;
}

'백준' 카테고리의 다른 글

1914 하노이탑  (0) 2021.12.20
1541 잃어버린 괄호  (0) 2021.12.14
1024 수열의 합 [미완]  (0) 2021.10.15
1182 부분수열의 합  (0) 2021.10.11
14930 구슬 (BEAD)  (0) 2021.10.11