Last active
October 5, 2021 00:25
-
-
Save PedroRacchetti/8525c75ac57f614d553a8827d886b38e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Comentário NOIC - OBI Fase 3 P1 e P2 - Festa | |
// Complexidade: O(M + Nˆ2) | |
// Escrito por Pedro Racchetti | |
#include<bits/stdc++.h> | |
using namespace std; | |
const int MAXM = 15; | |
vector<int> fila; | |
int n, m; | |
int t[MAXM]; | |
int main(){ | |
scanf("%d", &n); | |
scanf("%d", &m); | |
for(int i = 1; i <= m; i++) scanf("%d", &t[i]); | |
for(int i = 0; i <= n; i++) fila.push_back(i); | |
// inicializamos os vetores. Note que colocamos 0 na fila, | |
// para facilitar os indices posteriormente. | |
for(int i = 1; i <= m; i++){ | |
// manteremos um vetor para guardar os indices que devem ser deletados. | |
vector<int> toremove; | |
for(int j = t[i]; j < fila.size(); j += t[i]){ | |
toremove.push_back(j); | |
} | |
// para se manter a ordem, passamos de tras pra frente no vector de remoção. | |
for(int j = toremove.size() - 1; j >= 0; j--){ | |
fila.erase(fila.begin() + toremove[j]); | |
} | |
} | |
// agora, basta imprimir os números que permaneceram na fila. | |
for(int i = 1; i < fila.size(); i++){ | |
printf("%d\n", fila[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment