ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1124. Mosaic

how to do?
Posted by Czw's Brother 10 May 2004 13:13
Just build a graph.
Posted by Vlad Veselov 11 May 2004 18:16
Re: how to do?
Posted by LSBG 3 Oct 2008 14:07
My solution is the following:
First read the input and count how many pieces are placed in the wrong boxes(i.e. there color is not the same as the color of the box) lets call that number cnt. You must move these pieces at least once.
Then I build a graph for which the boxes are the nodes and there is an edge between two boxes a and b iff there is a piece of color b in the box of color a. After building the graph one should count the number of connected components in it(lets call it count).
Now the answer to our problem is simply cnt + max(count-1,0)
as one should do at least max(count-1,0) moving of his hand to another box and it is always possible to solve the problem in exactly that many moves of the hand without moving a piece.
Re: how to do?
Posted by Snooper 8 Oct 2012 02:55
LSBG, thank you so much, it's the better solution I've ever seen)))