Post
by Vegeta » Mon Jun 28, 2004 2:56 am
I am receiving WA too. I test my code with the inputs and its OK. Here's my code:
[c]#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int n, z, i, j, x, y, v;
int level;
int mat[25];
int pos[5], resp[5];
int min_total, min_cada, min_temp;
void Testa()
{
min_temp = 0;
for (i = 0; i < 25; i++)
if (mat > 0)
{
min_cada = 1e9;
for (j = 0; j < 5; j++)
{
v = mat * (abs(pos[j] / 5 - i / 5) + abs(pos[j] % 5 - i % 5));
if (v < min_cada)
min_cada = v;
}
min_temp += min_cada;
}
if (min_temp < min_total)
{
min_total = min_temp;
memcpy(resp, pos, sizeof(pos));
}
}
void Back(int limit)
{
int i;
if (level == 5)
Testa();
else
for (i = 4 - level; i < limit; i++)
{
pos[level++] = i;
Back(i);
level--;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("10660.in", "rb", stdin);
#endif
scanf("%d\n", &z);
while (z--)
{
scanf("%d\n", &n);
memset(mat, 0, sizeof(mat));
for (i = 0; i < n; i++)
{
scanf("%d %d %d\n", &x, &y, &v);
mat[x * 5 + y] = v;
}
min_total = 1e9;
level = 0;
Back(25);
for (i = 4; i >= 0; i--)
{
if (i != 4) printf(" ");
printf("%d", resp);
}
printf("\n");
}
return 0;
}
[/c]