Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
Back to list of problems

Simulation Wizardry

114.c

#include <stdio.h>

struct point {
	int obs;
	int score;
	int cost;
} puntos[52][52];

int m, n;
int tot_score=0;

int
movement(int * x, int * y, int * dir, int * lt)
{
	int newx=*x, newy=*y;
	int score=0;

	(*lt)--;
	if (*lt<=0) {
		return 0;
	}
	switch(*dir) {
		case 0: newx += 1; break;
		case 1: newy += 1; break;
		case 2: newx -= 1; break;
		case 3: newy -= 1; break;
	}
	if (puntos[newx][newy].obs) {
		score = puntos[newx][newy].score;
		*lt -= puntos[newx][newy].cost;
		newx=*x;
		newy=*y;
		*dir=(*dir+3)%4;
	}
	*x=newx;
	*y=newy;
	return score;
}


int
main(void)
{
	int p;
	int i,j;
	int c;
	int x, y, valor, coste, dir, lt;
	int score;

	scanf("%d %d", &m, &n);
	scanf("%d", &c);
	scanf("%d", &p);
	for(i=1; i<=m; i++) {
		for(j=1; j<=n; j++) {
			if (i==1 || j==1 || i==m || j==n) {
				puntos[i][j].obs=1;
				puntos[i][j].score=0;
				puntos[i][j].cost=c;
			} else {
				puntos[i][j].obs=0;
			}
		}
	}

	for(i=0; i<p; i++) {
		scanf("%d %d %d %d", &x, &y, &valor, &coste);
		puntos[x][y].obs=1;
		puntos[x][y].score=valor;
		puntos[x][y].cost=coste;
	}
	while(scanf("%d %d %d %d", &x, &y, &dir, &lt)==4) {
		score=0;
		while(lt>0) {
			score += movement(&x, &y, &dir, &lt);
		}
		printf("%d\n", score);
		tot_score += score;
	}
	printf("%d\n", tot_score);

	exit(0);
}