UVa 321 The New Villa ( BFS + 状态压缩判重)

题意:有几个房间,从一个房间开始走,进入另一个房间的要求是灯要亮着,而且两个房间之间是连通的。题目会给出房间的控制开关,也就是哪个房间的开关可以控制哪一个房间的开关。输入有房间数,房间的连接数,和开关控制数,要求从走廊开始,走到卧室,而且最后只有卧室的灯是开着的,别的房间的灯都是关着的

那么这道题要注意的是,一个操作是一步,要求输出走到卧室的最少操作,以及操作的顺序

关键在于建图和判重,其他的就是BFS的模板即可

由于要记录操作顺序,所以节点的结构设置也比较重要


 The New Villa 

Mr. Black recently bought a villa in the countryside. Only one thingbothers him: although there are light switches in most rooms, the lightsthey control are often in other rooms than the switches themselves.While his estate agent saw this as a feature, Mr. Black has come tobelieve that the electricians were a bit absent-minded (to putit mildly) when they connected the switches to the outlets.

One night, Mr. Black came home late. While standing in the hallway,he noted that the lights in all other rooms were switched off.Unfortunately, Mr. Black was afraid of the dark, so he never dared to entera room that had its lights out and would never switch off the lightsof the room he was in.

After some thought, Mr. Black was able to use the incorrectly wiredlight switches to his advantage. He managed to get to his bedroom and toswitch off all lights except for the one in the bedroom.

You are to write a program that, given a description of a villa,determines how to get from the hallway to the bedroom if only the hallwaylight is initially switched on. You may never enter a dark room, and afterthe last move, all lights except for the one in the bedroom mustbe switched off. If there are several paths to the bedroom, you haveto find th

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值