Cod sursa(job #723957)
| Utilizator | Data | 26 martie 2012 08:38:18 | |
|---|---|---|---|
| Problema | Stramosi | Scor | 60 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.4 kb |
#include <stdio.h>
unsigned N,M,O[250001],T,R;
int main()
{ FILE *f=fopen("stramosi.in","r");
fscanf(f,"%u %u",&N,&M);
unsigned i=1;
while(i<=N)
{ fscanf(f,"%u",&O[i]);
i++;
}
FILE *g=fopen("stramosi.out","w");
while(M)
{ fscanf(f,"%u %u",&T,&R);
O[0]=O[T];
R--;
while(R)
{ O[0]=O[O[0]];
R--;
}
fprintf(g,"%u\n",O[0]);
M--;
}
fclose(g);
fclose(f);
}
