Cod sursa(job #532041)

Utilizator feelshiftFeelshift feelshift Data 10 februarie 2011 19:05:32
Problema Curcubeu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
// http://infoarena.ro/problema/curcubeu
#include <fstream>
#include <cstdio>
using namespace std;

#define maxSize 5

ifstream in("curcubeu.in");
// cu ofstream nu intra in timpul de executie
FILE *out=fopen("curcubeu.out","wt");

struct stuff {
	int start,stop;
	int color;
};

int nrHouses;
int following[maxSize];
int house[maxSize];
stuff toPaint[maxSize];

int main() {
	in >> nrHouses >> toPaint[1].start >> toPaint[1].stop >> toPaint[1].color;

	for(int i=2;i<=nrHouses;i++) {
		toPaint[i].start = ((long long)toPaint[i-1].start * i) % nrHouses;
		toPaint[i].stop = ((long long)toPaint[i-1].stop * i) % nrHouses;
		toPaint[i].color = ((long long)toPaint[i-1].color * i) % nrHouses;

		int aux = max(toPaint[i].start,toPaint[i].stop);
		toPaint[i].start = min(toPaint[i].start,toPaint[i].stop);
		toPaint[i].stop = aux;
	}

	for(int i=1;i<=nrHouses;i++)
		following[i] = i + 1;

	for(int i=nrHouses-1;i>=1;i--)
		for(int k=toPaint[i].start;k<=toPaint[i].stop;) {
			if(!house[k])
				house[k] = toPaint[i].color;

			int aux = k;
			k = following[k];
			following[aux] = toPaint[i].stop + 1;
		}

	for(int i=1;i<=nrHouses-1;i++)
		fprintf(out,"%d\n",house[i]);

	in.close();

	return (0);
}