Topic Link:
Uva:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&itemid=8&category=24&page=show_ problem&problem=257
POJ 1137:http://poj.org/problem?id=1137
Zoj 1301:http://acm.zju.edu.cn/onlinejudge/showproblem.do?problemcode=1301
Type: Implicit graph Search
Original title:
Mr Black recently bought a villa the countryside. Only one thing bothers him:although there are light switches in most rooms, the lights they control are often into other RO OMS than the switches themselves. While he estate agent saw this as a feature, Mr. Black has come to believe that electricians were a bit absent-minded (to put it mildly) when they connected the switches to the outlets.
One night, Mr Black came home late. While standing in the hallway, he noted the lights in all other rooms were. Unfortunately, Mr Black is afraid of the dark, so he never dared to enter a room that had it lights out and would never Switch off the lights of the room he is in.
After some thought, Mr. Black is able to the incorrectly wired light switches to his advantage. He managed to the "bedroom" and "to" switch off all lights except for the one in the bedroom.
You are are to write a on that, given a description of a villa, determines how to get from the hallway to the bedroom if Only the hallway light are initially switched on. You could never enter a dark room, and after the "Last move" all lights except for the "one in" bedroom must be switched of F. If there are several paths to the bedroom, you have to find the one which uses the smallest number of steps, where ' Mo ve from one room to another "," switch on a light ' and "switch off a light '" each count as one step.
Sample Input
3 3 4
1 2 1 3 3 2 1 2 1 3 2 1 3 2 2 1 2 2 1 1 1 1 2 0 0-0
Sample Output
Villa #1 The
problem can solved in 6 steps:
-Switch on light in Room 2.
-Switch on light in Room 3.
-Move to Room 2.
-Switch off light in Room 1.
-Move to Room 3.
-Switch off light in Room 2.
Villa #2 The
problem cannot be solved.
The main effect of the topic:
A 2B youth makes money and runs cheerfully to buy a villa, it turns out that the light circuit of the villa is wrong, the light switch in each room is not controlled by the light in the room, but the electric light in the other room. 2B Youth very angry, the consequences are very serious, so seriously condemned the decoration workers.
One night the 2B youth returned home, standing in the hall, and found that all but the other rooms in the hall were extinguished. 2 b Young people are afraid of the dark, dare not go into the room without lights. So the question is, how should he walk from the hall to his bedroom?
2 b Young people are still very smart, he found that it was possible to use the light switch to connect the lights on the other room and then walk into the room where the light was turned on (2 B youth would not have to wear walls, so the two rooms must be adjacent and have doors).
2 b Youth is also a very thrifty young man, so when he went to the bedroom, he asked the other rooms to be destroyed.
Now is your time to make a point, write a program to help 2B youth to find a program with the least steps and output. Turning on the light, turning off the light and walking into the other room is a step. If you can't find a plan, 2B youth will have to sleep on the lobby couch tonight.