i need help on this problem as well. my code works well on the judge's input.
but it gives me a TIME LIMIT. i don't see why. this problem has a low complexity.
here's my program:
[c]#include <stdio.h>
#include <stdlib.h>
#define MMAX 51
#define NMAX 51
#define NOBUMP -1
int grid[MMAX][NMAX];
int m,n,wallcost,nbumpers;
typedef struct cost { int pointsup, lifedown; } cost;
struct _ball { int x,y,dir,pts,life; } ball;
cost *bumpers;
char init()
{
int x,y,i,j;
scanf("%d%d%d%d",&m,&n,&wallcost,&nbumpers);
for (i=1;i<m-1;i++)
for (j=1;j<n-1;j++)
grid[j] = NOBUMP;
for (i=0;i<m;i++)
{
grid[0] = 0;
grid[n-1] = 0;
}
for (j=0;j<n;j++)
{
grid[0][j] = 0;
grid[m-1][j] = 0;
}
if ((bumpers = (cost *)malloc((nbumpers+1)*sizeof(cost))) == NULL)
return 0;
bumpers[0].pointsup = 0;
bumpers[0].lifedown = wallcost;
for (i=1;i<=nbumpers;i++)
{
scanf("%d%d%d%d",&x,&y,&bumpers.pointsup,&bumpers.lifedown);
grid[x][y] = i;
}
return 1;
}
note that coordinates in my program go from 0 ot m-1 and 0 to n-1.
also i assumed walls were within the grid. ie playground 4x4 means only 2x2 "non-wall" positions.
[c]#include <stdio.h>
#include <stdlib.h>
#define MMAX 51
#define NMAX 51
#define NOBUMP -1
int grid[MMAX][NMAX];
int m,n,wallcost,nbumpers;
typedef struct cost { int pointsup, lifedown; } cost;
struct _ball { int x,y,dir,pts,life; } ball;
cost *bumpers;
char init()
{
int x,y,i,j;
scanf("%d%d%d%d",&m,&n,&wallcost,&nbumpers);
for (i=1;i<m-1;i++)
for (j=1;j<n-1;j++)
grid[j] = NOBUMP;
for (i=0;i<m;i++)
{
grid[0] = 0;
grid[n-1] = 0;
}
for (j=0;j<n;j++)
{
grid[0][j] = 0;
grid[m-1][j] = 0;
}
if ((bumpers = (cost *)malloc((nbumpers+1)*sizeof(cost))) == NULL)
return 0;
bumpers[0].pointsup = 0;
bumpers[0].lifedown = wallcost;
for (i=1;i<=nbumpers;i++)
{
scanf("%d%d%d%d",&x,&y,&bumpers.pointsup,&bumpers.lifedown);
grid[x-1][y-1] = i;
}
return 1;
}
Can you help me to give some test case for this problem, because I always got WA for this problem but I don't know why.
Maybe my description wrong or ???? but based on all previous post for this problem I thinks my description true. maybe I missing something ?
please help me. i dont know why i keep getting wa for this prob.
here is my code
[c]#include<stdio.h>
struct grid
{
int obstacle;
int value;
int cost;
};
struct ball
{
int px;
int py;
int d;
int life;
};
void resolve(int a,int *ax,int *ay)
{
switch(a)
{
case 0 : *ax=1; *ay=0; break;
case 1 : *ax=0; *ay=1; break;
case 2 : *ax=-1; *ay=0; break;
case 3 : *ax=0; *ay=-1;
}
}