0
I made the point The Legend of Flavious Josephus, but the time limit has expired, which I can change to decrease the time
My code
#include <stdio.h>
void carregaVetor(int *vetor, int numero);
void removeNum(int *vetor, int *cont, int *tam, int *indice);
void removeElem(int *vetor, int *posicao, int *tam, int *cont);
int main(int argc, char** argv)
{
int vetor[90000], cont = 0, tam, indice = 0, posi;
int teste, numero, pulo, i;
while(scanf("%d", &teste) != EOF)
{
for(i = 0; i < teste; i++)
{
scanf("%d %d", &numero, &pulo);
tam = numero;
carregaVetor(vetor, numero);
while(tam != 1)
{
cont = posi = indice = 0;
while(indice != (pulo - 1))
{
removeNum(vetor, &cont, &tam, &indice);
}
cont = 0;
while(cont != pulo)
{
removeElem(vetor, &posi, &tam, &cont);
}
}
printf("Case %d: %d\n", i + 1 , vetor[0]);
}
}
return 0;
}
void carregaVetor(int *vetor, int numero)
{
int i;
for(i = 0; i < numero; i++)
{
vetor[i] = i + 1;
}
}
void removeNum(int *vetor, int *cont, int *tam, int *indice)
{
(*tam)++;
vetor[*tam] = vetor[*indice];
(*cont)++;
(*indice)++;
}
void removeElem(int *vetor, int *posicao, int *tam, int *cont)
{
int i;
for(i = (*posicao); i < (*tam); i++)
{
vetor[i] = vetor[i + 1];
}
(*tam)--;
(*cont)++;
}
A doubly chained list could make the code more efficient ?
– Igor PTZ