11214 - Guarding the Chessboard
Moderator: Board moderators
11214 - Guarding the Chessboard
some hints to optimize it.
-
- New poster
- Posts: 44
- Joined: Tue Jun 06, 2006 6:44 pm
- Location: Nova Scotia, Canada
- Contact:
(Oops... last time I was here there wasn't a post, ah well... might as well delete my old one)
I'm getting WA.. can someone explain why my algorithm won't work?
It is..
minQueens = 0
While boardNotEmpty:
PlaceQueenWhichEliminatesLargestNumberOfX's
EliminateX'sForThatQueen
minQueens ++
Loop.
Judging by the times of the other submissions, and the time of my WA -- I'm guessing my greedy algorithm is wrong, I'd like to know why though...
If it is infact wrong, would branching when there are multiple best-placed-queens help? hmm...
P.S.
Input:
My WA Output:
Thanks in advance.
I'm getting WA.. can someone explain why my algorithm won't work?
It is..
minQueens = 0
While boardNotEmpty:
PlaceQueenWhichEliminatesLargestNumberOfX's
EliminateX'sForThatQueen
minQueens ++
Loop.
Judging by the times of the other submissions, and the time of my WA -- I'm guessing my greedy algorithm is wrong, I'd like to know why though...
If it is infact wrong, would branching when there are multiple best-placed-queens help? hmm...
P.S.
Input:
Code: Select all
8 8
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
8 8
X.......
.X......
..X.....
...X....
....X...
.....X..
......X.
.......X
9 2
XX
XX
XX
XX
XX
XX
XX
XX
XX
2 2
XX
XX
5 3
XXX
XXX
XXX
XXX
...
9 9
.X.......
........X
.........
.........
.........
...X.....
.........
..X......
.....X...
9 9
XXXXXXXXX
XXXXXXXXX
XXXX.XXXX
XXX.X.XXX
XX.X.X.XX
XXX.X.XXX
XXXX.XXXX
XXXXXXXXX
XXXXXXXXX
2 2
..
..
0
Code: Select all
Case 1: 5
Case 2: 1
Case 3: 2
Case 4: 1
Case 5: 2
Case 6: 2
Case 7: 5
Case 8: 0
- Chris Adams
Your outputs are correct. Greedy shouldn't work I think. Check the case below.
Input:
Output:
Hope it helps.
Input:
Code: Select all
5 5
XX...
XX...
X...X
X..X.
XXXXX
0
Code: Select all
2
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- New poster
- Posts: 44
- Joined: Tue Jun 06, 2006 6:44 pm
- Location: Nova Scotia, Canada
- Contact:
Try the case.
Input:
Output:
Hope it helps.
Input:
Code: Select all
7 7
X......
XX.....
X.X..X.
X......
X..X...
X......
XXXXXXX
0
Code: Select all
2
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- New poster
- Posts: 44
- Joined: Tue Jun 06, 2006 6:44 pm
- Location: Nova Scotia, Canada
- Contact:
Err... This time your code should fail I think...Otherwise, if you dont mind, post your code.
Input:
And output is 2.
Input:
Code: Select all
7 7
X......
XX.....
X.X..X.
X......
X..X.X.
X......
XXXXXXX
0
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- New poster
- Posts: 44
- Joined: Tue Jun 06, 2006 6:44 pm
- Location: Nova Scotia, Canada
- Contact:
-
- New poster
- Posts: 44
- Joined: Tue Jun 06, 2006 6:44 pm
- Location: Nova Scotia, Canada
- Contact:
Yep, that is exactly how I worried when designing test cases. So I used a few pairs of test cases with exactly one different square (marked vs unmarked) that have different answers. But I'm still unsure a clever "detector" would defeat my data... So if you succeeded one day, please tell meLithiumDex wrote:I have the running theory.. that in the rare(?) case that the greedy algorithm fails, it will only be off by one -- I wonder if there's some way to detect this case quickly and subtract one? hmm...


-
- New poster
- Posts: 4
- Joined: Sat Sep 16, 2006 9:55 am
6 5
XXXXX
XXXXX
XXX..
X.XX.
X..XX
X...X
5 6
XXXXXX
XXX...
XXXX..
XX.XX.
XX..XX
5 6
XXXXXX
...XXX
..XXXX
.XX.XX
XX..XX
6 5
XXXXX
XXXXX
..XXX
.XX.X
XX..X
X...X
0
For all this test case output is 2.
But type of the 2 and 3 no of test case is not in the judge test case
because one of my accepted code is fail generate this output.
XXXXX
XXXXX
XXX..
X.XX.
X..XX
X...X
5 6
XXXXXX
XXX...
XXXX..
XX.XX.
XX..XX
5 6
XXXXXX
...XXX
..XXXX
.XX.XX
XX..XX
6 5
XXXXX
XXXXX
..XXX
.XX.X
XX..X
X...X
0
For all this test case output is 2.
But type of the 2 and 3 no of test case is not in the judge test case
because one of my accepted code is fail generate this output.
Ways to Optimize
Hi,
About the question on how to optimize...
I got 30 milliseconds using
branch and bound Heuristic Search.
About the question on how to optimize...
I got 30 milliseconds using
branch and bound Heuristic Search.