Cod sursa(job #1748894)

Utilizator DevilOnFieldTudor Horia Niculescu DevilOnField Data 27 august 2016 11:05:45
Problema Curcubeu Scor 70
Compilator c Status done
Runda Arhiva de probleme Marime 1.2 kb
#include<stdio.h>

FILE *in, *out;

struct pictam
{
	int st, dr, hue;
};

struct pictam colo[1000000];
int nxgol[1000001], n;

void initializ(int n, long long a, long long b, long long c)
{
	long long i, ap, bp;

	for(i = 1; i <= n-1; i++) {
		nxgol[i] = i;
	}

	i = 1;

	do {
		if(a > b) {
			ap = b;
			bp = a;
		} else {
			ap = a;
			bp = b;
		}
		colo[i].st = ap;
		colo[i].dr = bp;
		colo[i].hue = c;
		i++;
		a = (a * i) % n;
		b = (b * i) % n;
		c = (c * i) % n;
	} while(i < n);
/*
	for(i = 1; i < n; i++) {
		printf("%d %d %d\n", colo[i].st, colo[i].dr, colo[i].hue);
	}
//*/
}

int cap(int x)
{
	if(nxgol[x] != x) {
		nxgol[x] = cap(nxgol[x]);
	}
	return x;
}

int pictu[1000001];

int main ()
{
	long long a, b, c;
	int i, j;

	in = fopen("curcubeu.in", "r");
	out = fopen("curcubeu.out", "w");

	fscanf(in, "%d%lld%lld%lld", &n, &a, &b, &c);

	initializ(n, a, b, c);

	for(i = n - 1; i >= 1; i--) {
		j = colo[i].st;
		while(j <= colo[i].dr) {
			if(nxgol[j] == j) {
				nxgol[j] = cap(colo[i].dr);
				if(pictu[j] == 0) {
					pictu[j] = colo[i].hue;
				}
				j++;
			} else {
				j = cap(nxgol[j]);
			}
		}
	}

	for(i = 1; i < n; i++) {
		fprintf(out, "%d\n", pictu[i]);
	}

	fclose(in);
	fclose(out);

	return 0;
}