10937 - Blackbeard the Pirate
Moderator: Board moderators
10937 - Blackbeard the Pirate
Can I assume there is exactly one landing point '@'?
I think this one is almost the same as 10818 (Dora Trip), but I got WA with the modified code from 10818.
I think this one is almost the same as 10818 (Dora Trip), but I got WA with the modified code from 10818.
Originally, I use the following code to check whether (r, c) is safe from the angry natives:
Then, (r, c) is a safe location iff i==8. However, the above code forget to check whether 0<=r+dy<h && 0<=c+dx<w.
Code: Select all
int dx[]={1,1,0,-1,-1,-1,0,1}, dy[]={0,-1,-1,-1,0,1,1,1};
for(i=0; i<8 && map[r+dy[i]][c+dx[i]]!='*'; i++);
i think there's something wrong in the test case...
for(i = 1; i <= h; i ++)
{
scanf("%s", &map[1]);
for(j = 1; j <= w; j ++)
{
if (map[j] == '@') st = pr(i, j);
else if (map[j] == '!')
{
trea[nt ++] = pr(i, j);
map[j] = nt;
}
//when i added following code,i got a tle...
//if (map[j] != '*' && map[j] != '.'
//&&map[j] != '~' && map[j] != '#'
//&&map[j] != '!' && map[j] != '@') while(1);
}
}
and after i considered every symbol not in the list as '#' i got acc...
{
scanf("%s", &map[1]);
for(j = 1; j <= w; j ++)
{
if (map[j] == '@') st = pr(i, j);
else if (map[j] == '!')
{
trea[nt ++] = pr(i, j);
map[j] = nt;
}
//when i added following code,i got a tle...
//if (map[j] != '*' && map[j] != '.'
//&&map[j] != '~' && map[j] != '#'
//&&map[j] != '!' && map[j] != '@') while(1);
}
}
and after i considered every symbol not in the list as '#' i got acc...
-
- Learning poster
- Posts: 58
- Joined: Wed Dec 31, 2003 8:43 am
- Location: Dhaka, Bangladesh
- Contact:
Re: i think there's something wrong in the test case...
thx chanson, finally i just get accepted after 10/12 submissions. I never considered abt dirty input.chanson wrote: and after i considered every symbol not in the list as '#' i got acc...
-
- New poster
- Posts: 2
- Joined: Sun May 06, 2012 7:41 pm
Re: 10937 - Blackbeard the Pirate
replace every unnecessary characters with '#' , then use BFS(n times) to find all pair shortest path.
Then use the TSP algorithm
check this input
3 3
..*
.@.
.!~
3 3
.!*
...
.@~
output :
-1
-1
Then use the TSP algorithm
check this input
3 3
..*
.@.
.!~
3 3
.!*
...
.@~
output :
-1
-1