229 - Scanner

All about problems in Volume 2. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
liulike
Learning poster
Posts: 52
Joined: Wed Jul 30, 2003 10:56 am

229 - Scanner

Post by liulike »

How to solve it ?
THX!
liulike
Learning poster
Posts: 52
Joined: Wed Jul 30, 2003 10:56 am

Post by liulike »

:oops:
howardcheng
Learning poster
Posts: 71
Joined: Thu Aug 21, 2003 1:56 am

Post by howardcheng »

Is it true that one doesn't need to backtrack? i.e. if there is a scan line with imperfect information, then we can pick any cell and color it either way and still get a solution (assuming a solution exists). I believe I have a proof of this, but my program is giving me wrong answer. An assertion shows that there is at least one case has triggers this condition.

I don't know if my proof is wrong or my implementation is wrong...
liulike
Learning poster
Posts: 52
Joined: Wed Jul 30, 2003 10:56 am

Post by liulike »

Any one else?
Plz give me some hint?

Thank you all!
Quantris
Learning poster
Posts: 80
Joined: Sat Dec 27, 2003 4:49 am
Location: Edmonton AB Canada

Post by Quantris »

howard, what exactly do you mean?

how are you checking for ambiguous cases (more than one solution)?
howardcheng
Learning poster
Posts: 71
Joined: Thu Aug 21, 2003 1:56 am

Post by howardcheng »

What I mean is this:

- if there is a scanline in which the number of black cells is the same as the number of cells in the line, then you can fill the whole line black

- similarly, if there is a scanline with no black cells then all cells are white

- every time we fill in some cells (black/white) we have to update the counts.

So we repeatedly look for scanlines which are either completely black or completely white (for the undetermined cells). My claim is that if there is some cell which has not been filled but there is no scanline with complete information, then coloring this cell either way will lead to a valid solution (assuming that there was a solution to begin with).
Andrew Neitsch
New poster
Posts: 43
Joined: Fri Jun 25, 2004 9:37 pm

Post by Andrew Neitsch »

Do you know why it is a special corrector problem?
howardcheng
Learning poster
Posts: 71
Joined: Thu Aug 21, 2003 1:56 am

Post by howardcheng »

No idea.
bors
New poster
Posts: 1
Joined: Sat Dec 03, 2005 10:57 am
Location: France

Post by bors »

Hi!

I keep getting WA for this one.

My test input is currently :

Code: Select all

7
10 10 6 4 6 8 13 15 11 6
0 1 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....
....######.....
......####.....
.......####..##
.......########
#####..########
###############
..#########..##
....######.....

...............
...............
...............
...............
...............
...............
...............
...............
...............
...............

...#########...
..###########..
.....#####.....
......####.....
.......#......#
.......#......#
##.....#.....##
##############.
..#########....
....######.....

...............
...............
...............
......#####....
.....#....##...
....#......##..
.#############.
.#############.
..##......##...
...............

...............
.#############.
.#...........#.
.#.#########.#.
.#.#.......#.#.
.#.#.......#.#.
.#.#########.#.
.#...........#.
.#############.
...............

.#...#.....#...
.######...###..
.######..####..
...###...####..
...###..######.
..#############
..#####..######
.#####.....###.
.#.###.........
....#..........

...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
Could anyone check my output and give me some other input to try ?

Thanks in advance.
sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Location: Vancouver, BC, Canada
Contact:

Post by sclo »

Remember that the input doesn't need to correspond to a valid scan. The sensor data could be too high or too low for any images found by backtracking.

Also, I've checked the judge that backtracking is absolutely needed, just computing without backtracking will not solve some inputs. A hybrid of backtracking and computing must be done. There are unambiguous cases that contains undetermined squares that can't be solved using Howard's method.

The output given above is CORRECT.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 229 Scanner

Post by brianfry713 »

I solved it without backtracking.

Code: Select all

set all cells to unknown

do {
  for every scan line {
    count the number of unknown, blank, and filled cells
    if the count of filled cells equals the number of filled cells, then change unknown cells to blank
    if the count of unknown cells plus the count of filled cells equals the number of filled cells, then change unknown cells to filled
  }
} while(a cell was modified)

If any cells are unknown or any scan line's count of filled cells doesn't equal the number of filled cells, then print a blank grid, otherwise print the completed grid.
Check input and AC output for thousands of problems on uDebug!
pritorius
New poster
Posts: 1
Joined: Fri Aug 23, 2013 7:34 am
Location: Wichita, KS
Contact:

Re: 229 Scanner

Post by pritorius »

Hi BrianFry,

Thanks for sketching out the algo. Will try it.
Post Reply

Return to “Volume 2 (200-299)”