Pagini recente » Cod sursa (job #2635403) | Cod sursa (job #1657517) | Cod sursa (job #3211964) | Cod sursa (job #256332) | Cod sursa (job #527257)
Cod sursa(job #527257)
// p010.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
//#include <cstdlib>
#include "stdio.h"
int main()
{
FILE *f = fopen("C:\\stramosi.in", "rt");
FILE *fres = fopen("c:\\stramosi.out", "wt");
if (!f || !fres)
return 0;
int n = 0, m = 0;
fscanf(f, "%d%d", &n, &m);
int mat[20][250002] = {{ 0 }};
int i = 0, j = 0;
for (i = 1; i <= n; i++)
fscanf(f, "%d", &mat[0][i]);
/* bool cont = true;
for (i = 1; cont; i++)
{
cont = false;
for (j = 1; j <= n; j++)
{
mat[i][j] = mat[i - 1][mat[i - 1][j]];
if (mat[i][j] != 0)
cont = true;
}
}*/
/* int q = 0, p = 0;
for (i = 0; i < m; i++)
{
fscanf(f, "%d %d", &q, &p);
//q = rand() % 18 + 1;
//p = rand() % 250000 + 1;
// al p-lea stramos al lui q
while (p > 0 && q != 0)
{
int pow = 1, c = 0;
while (pow * 2 <= p)
{
pow *= 2;
c++;
}
q = mat[c][q];
p -= pow;
}
fprintf(fres, "%d\n", q);
}*/
fclose(fres);
fclose(f);
return 0;
}