Photolog
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, <)==4) {
score=0;
while(lt>0) {
score += movement(&x, &y, &dir, <);
}
printf("%d\n", score);
tot_score += score;
}
printf("%d\n", tot_score);
exit(0);
}









