zoj1301 The New Villa

用Verilog手把手教你搭建一个5级流水线的MIPS CPU(附完整代码与仿真) 本文详细介绍了如何使用Verilog从零构建一个5级流水线的MIPS处理器,包括开发环境配置、核心模块实现、流水线冲突处理等关键技术。通过完整的代码示例和仿真方法,帮助读者掌握CPU设计的基本原理和实践技巧,特别适合想要入门处理器设计的工程师和学习者。 阅读详情
 
The New Villa

Time limit: 1 Seconds   Memory limit: 32768K   Special Judge
Total Submit: 1036   Accepted Submit: 331  

Mr. Black recently bought a villa in the countryside. Only one thing bothers him: although there are light switches in most rooms, the lights they control are often in other rooms than the switches themselves. While his estate agent saw this as a feature, Mr. Black has come to believe that the 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 that the lights in all other rooms were switched off. Unfortunately, Mr. Black was afraid of the dark, so he never dared to enter a room that had its lights out and would never switch off the lights of the room he was in.

After some thought, Mr. Black was able to use the incorrectly wired light switches to his advantage. He managed to get to his bedroom and to switch 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 hallway light is initially switched on. You may never enter a dark room, and after the last move, all lights except for the one in the bedroom must be switched off. If there are several paths to the bedroom, you have to find the one which uses the smallest number of steps, where ``move from one room to another'', ``switch on a light'' and ``switch off a light'' each count as one step.


Input

The input contains several villa descriptions. Each villa starts with a line containing three integers r, d, and s. r is the number of rooms in the villa, which will be at most 10. d is the number of doors/connections between the rooms and s is the number of light switches in the villa. The rooms are numbered from 1 to r; room number 1 is the hallway, room number r is the bedroom.

This line is followed by d lines containing two integers i and j each, specifying that room i is connected to room j by a door. Then follow s lines containing two integers k and l each, indicating that there is a light switch in room k that controls the light in room l.

A blank line separates the villa description from the next one. The input ends with a villa having r = d = s = 0, which should not be processed.


Output

For each villa, first output the number of the test case (`Villa #1', `Villa #2', etc.) in a line of its own.

If there is a solution to Mr. Black's problem, output the shortest possible sequence of steps that leads him to his bedroom and only leaves the bedroom light switched on. (Output only one shortest sequence if you find more than one.) Adhere to the output format shown in the sample below.

If there is no solution, output a line containing the statement `The problem cannot be solved.'

Output a blank line after each test case.


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 be 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.

 

msfvenom制作windows/linux/android/ios木马 msfvenom选项如下 -p, --payload<payload> 指定 payload(攻击荷载)。如果使用自定义payload,请使用'-'或者stdin指定。 -l, --list [module_typel列出指定模块的所有可用资源。模块类型包括:payloads, encoders, nops, all -n, --nopsled <length>为payload预先指定一个NOP滑动长度。 -f, --format <format>指定输出格式(使 阅读详情

相关推荐

树莓派4B安装 ubuntu20.04 & VNC远程桌面 & 安装ROS noetic

树莓派4B安装ubuntu20.04 & VNC远程桌面1、安装ubuntu方式1:下载Imager文件。方式2:下载镜像文件。2、查询树莓派 IP 地址3、使用ssh远程登录树莓派4、更新源地址5、更新6、安装桌面环境7、允许root登陆8、登陆远程桌面9、设置中文 1、安装ubuntu 方式1:下载Imager文件。...

weixin_44415639的博客 2万+

zoj1301

zoj1301

zzu-hust-madd 301

汽车诊断服务(UDS——0x11服务解析)

ECU复位服务(0x11)详解:该服务支持硬件/钥匙开关/软件三种复位类型(0x01-0x03),复位前需发送肯定响应。请求格式为11+子功能,响应含51+子功能。典型应用需配合安全访问流程,测试时需监控CAN总线通信及DTC状态。复位后ECU将返回默认会话,期间不处理任何诊断请求。服务在编程会话且安全解锁后执行,硬复位会初始化存储数据。

从事汽车行业 993

zoj 1301 Color the Ball 区间合并线段树

Color the Ball 题意:一开始全部点为黑色,然后给n个区间染色,染色为白色或黑色,最后统计哪段区间白色最长,要最右边的。 这题因为没说区间有多少个点,所以一开始不知道线段树要维护多长的区间,但是操作只有2000种,所以离散化之后点数也就4000,但是如果本来不连续的区间,离散化后可能就连续了,为了解决这个,要在把L-1,R+1也加到离散化数组里总共8000个点,然后L~R之间的线段...

SEIZE THE DAY 218

第二十七届华东杯数学建模A 题 跳台滑雪问题 完整思路模型及代码

考虑到滑行过程中的空气阻力和摩擦力对速度的影响,我们引入了不同姿态下运动员迎风面积和空气阻力系数的变化,利用牛顿第二定律建立加速度表达式,并通过数值模拟比较常见姿态下的终端速度。针对问题二,我们构建了二维空中飞行动力学模型,结合起跳速度、身体迎角、滑雪板倾角等因素,模拟运动员在空中飞行的轨迹与姿态变化,采用欧拉法对运动过程进行仿真,优化飞行路径和稳定性。仿真结果表明,运动员应在起跳后保持滑雪板与身体成“V”字形打开、重心略后倾的姿态,以增强升力、延长飞行距离并提高姿态得分。,并模拟出跳跃的轨迹和最终得分。

lichensun的博客 3222

CVE-2017-7921漏洞深度解析:海康设备明文密码泄露原理与七层防御

网络摄像头安全本质上是嵌入式Web服务安全,其核心在于身份认证机制是否健全。CVE-2017-7921并非传统远程执行漏洞,而是因信任错位导致的未授权API暴露——`/Security/users/1`接口绕过Session校验,直接返回admin明文密码。该问题根植于安防设备早期‘物理隔离+前端可控’的设计假设,在P2P、云平台等新场景下全面失效。技术价值在于揭示了轻量级HTTP服务中路径级访问控制缺失的普遍风险;典型应用场景包括ONVIF协议接管、Telnet后门登录及NVR侧横向移动。本文基于DS-2

weixin_33324197的博客 545

Codeforces 467C George and Job【dp】好题~

C. George and Job time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The new ITone 6 has been released recently and Georg

mengxiang000000 1431

详细Ubuntu 22.04 配置最新UR机械臂仿真环境(ros2-humble, ur-sim, ur-ros2-driver)

使用ubuntu22.04.01和ur-sim, ur-driver进行ur机械臂的仿真

verloge的博客 1万+

zoj1301 Code

 #include #include #include using namespace std;struct status{ int lightBits, room, step; struct status *next;}status[1024][10];struct door{ int r1, r2;

yllfever的专栏 589

基于simulink的BMS系统中电池单体故障隔离与恢复建模

本文介绍了使用Simulink构建BMS电池单体故障诊断与容错控制模型的方法。主要内容包括:1)搭建12串锂电池组模型;2)实现单体故障注入(过压、断线等);3)设计故障诊断与隔离模块(采用Stateflow状态机);4)开发恢复判断逻辑(需满足电压、温度等条件);5)系统监控与仿真设置。文章还提供了工程实践建议,如防环流设计、通信冗余等,并指出进阶方向(多故障处理、AI预警等)。该模型适用于新能源汽车、储能系统的BMS设计,可提高系统可靠性和安全性。

xiaoheshang_123的博客 150

学Simulink--基于多物理场耦合与系统集成的储能系统场景实例:压缩空气储能(CAES)系统的热力学建模与效率分析

本文提供了一个基于Simulink的压缩空气储能(CAES)系统热力学建模教程。通过多物理场耦合方法,详细演示了从系统架构设计到仿真测试的全过程,包括多级压缩机/膨胀机系统搭建、显热蓄热系统设计以及效率分析。文章重点强调了热管理对提升CAES效率的关键作用,并给出了68%电-电效率的优化案例。最后提出了变工况建模、不同蓄热介质对比等高级优化方向,为开发零碳大容量储能系统提供了实用工具和方法。

amy_mhd的博客 143

ZOJ 1301 The New Villa (BFS + 状态压缩)

题意:黑先生新买了一栋别墅,可是里面的电灯线路的连接是很混乱的(每个房间的开关可能控制其他房间,房间数 写起来有些纠结(实力太弱)...........先对各个房间的灯进行操作,再考虑向其他房间走的问题。 由于要输出路径,所以添加前驱标识,递归输出即可。 #include #include #include #include using namespace std; int n,m,

Paradiser 1105

企业级OpenClaw部署实战:10个关键配置让你从“养虾“到“精通“

OpenClaw(社区昵称"小龙虾")作为2026年开源社区最活跃的AI Agent项目,凭借其多Agent协同架构和企业级安全隔离能力,已成为中大型企业的首选AI基础设施。本文基于真实企业部署经验,系统梳理了企业级OpenClaw部署的10个关键配置:用户ID消息隔离、群组ID消息隔离、多机器人配置、无限量Agent创建、机器人与Agent关联、Agent间调度、权限配置、Hooks任务、多模型切换及一键备份迁移。

program哲学 948

[ZOJ1301][POJ1137] The New Villa

ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1301POJ: http://poj.org/problem?id=1137题目大意:每个房间的开关经常是控制别的房间的灯的。

Dango's happy life 1090

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

zoj 1301 The New Villa

bfs

ZekiDai的博客 158

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

UVa 321 & ZOJ 1301 - The New Villa

传送门UVa 321 & ZOJ 1301 - The New Villa

一只冰熊 1126

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

UVa 321 The New Villa,2B青年怒找卧室

题目链接: 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.

D_Double's Journey 2624

The New Villa (Uva 321 bfs)

题意:有r个房间,一个人开始在1号房间并且1号房间灯亮着其他熄灭,现在要去r号房间,告诉d对房间之间有门,s个开关,每个房间i内开关控制的不是本房间的灯,而是另外一个房间j的灯,人每次可以开或关自己房间的开关,或移动到亮着的房间,不是亮着的不能进去,问最终到r号房间最少需要几个步骤,输出步骤。到r号房间后r号房间亮着其他熄灭。 思路:把r个房间灯的状态用01串表示,1表示亮着,0表示熄灭,人当前在的房间为2,这样初始状态为2000000,终态为0000002,map判重,bfs即可。

@you! 977

zoj 1011NTA

//#include #include #define MAXN 15 #define MAXK 10#define MAXL 10using namespace std;int m, n, k;struct mypair{ int a, b; mypair *next;

yllfever的专栏 1560

zoj 1028 Flip and Shift

/**证明: 首先, 若n为奇数,则必然可以完成任务 将n个球遍号为1,2,...,n 若从1位置开始,进行 n-1次连续的 (flip, shift, shift), 则 除了球1外, 所有球的位置都 减了2, 而球1最后到达原来球n-1的位置。(见图, 可以知道, 相当于交换球1和2的位置)

yllfever的专栏 1446

计算 高次幂相对某个模数的余( (a ^ n)mod p, n 很大 )

在做google codejam 2008 round 1A problem C 的 时候, 从别人代码里学到的 假如 要计算 (a ^ n) , n很大, 直接计算的话, 是个 O(n)的方法有 O(log (n))的方法,如下:       把n表示成2进制, n = n0 * 1 + n1 * 2 + n2 * 4 + ... + nk * (2^k)则    a^n =[

yllfever的专栏 1336

POJ1097 Roads Scholar

#include #include #include #include using namespace std;const int MAXN = 30;const int MAXDIST = 100000000;int distanc[MAXN][MAXN];//从交点a到b的最短距离 int dist[MAXN][MAXN];//从

yllfever的专栏 1188

zoj1155 triangle war

/**DP 对状态编号, 18条边, 每条边可能实线, 也可能虚线, 有2^18种MaxScore(x) = max {               StepScore(rCode, selectedEdgeNum) > 0            ?  StepScore + MaxScore(rCode)         //选择的边成三角行           

yllfever的专栏 1011

zoj 1038 T9 mobile input method

#include #include #include using namespace std;struct Key{ int num; char ch[4];};const Key keys[10] = { {}, {}, {3, {a, b,

yllfever的专栏 937

zoj 1166 Anagram Checker

/**A seach problem.**/#include  #include  #include  #include  #include  using namespace std;/**dictionary words**/string word[2000];/**Word in phrase**/string swo

yllfever的专栏 907
上一篇: zoj 1144 Robbery
下一篇: zoj1301 Code
yllfever
博客等级 码龄19年 4粉丝 44原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址