자라는 개발자/문제풀이

백준 c++ 15235 Olympiad Pizza

자란다 2022. 2. 10. 22:19
728x90
반응형

15235 Olympiad Pizza

문제 풀이

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
void fast_io(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main(void)
{
    fast_io();
    queue<pair<int, int>> q;
    int n, total = 0;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        total += t;
        q.push(make_pair(t, i));
    }
    for (int i = 1; i < total + 1; i++)
    {
        if (q.front().first > 1)
        {
            q.push(make_pair(q.front().first - 1, q.front().second));
        }
        else
        {
            v[q.front().second] = i;
        }
        q.pop();
    }
    for (int i = 0; i < n; i++)
        cout << v[i] << " ";
}

가지고싶은 만큼의 피자조각을 가졌을때 벡터에 몇번의 사람이 몇번째에 다 가졌는지 넣어주었다.

728x90
반응형

'자라는 개발자 > 문제풀이' 카테고리의 다른 글

백준 c++ 11656 접미사 배열  (0) 2022.02.18
백준 c++ 11170 0의 개수  (0) 2022.02.14
백준 c++ 15832 Aku Negaraku  (0) 2022.02.09
백준 c++ 14783 Eenie Meenie Miney Moe  (0) 2022.02.08
백준 c++ 1966 프린터 큐  (0) 2022.02.06