题目信息

题目类型
练习
题目年份
2025
题目题型
编程题
关 键 词
电路维修

题目题干

【例题1】电路维修

 

【题目描述】

译自 BalticOI 2011 Day1 T3「Switch the Lamp On」ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

有一种正方形的电路元件,在它的两组相对顶点中,有一组会用导线连接起来,另一组则不会。ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

有 N×M 个这样的元件,你想将其排列成 N 行 M 列放在电路板上。电路板的左上角连接电源,右下角连接灯泡。ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

【例题1】电路维修 【题目描述】 译自 BalticOI 2011 Day1 T3「Switch the Lamp On」  有一种正方形的电路元件,在它的两组相对顶点中,有一组会用导线连接起来,另一组则不会。  有 N×M 个这样的元件,你想将其排列成 N 行 M 列放在电路板上。电路板的左上角连接电源,右下角连接灯泡。    试求:至少要旋转多少个正方形元件才能让电源与灯泡连通,若无解则输出 NO SOLUTION。  Casper is designing an electronic circuit on a N×M rectangular grid plate. There are N×M square tiles that are aligned to the grid on the plate. Two (out of four) opposite corners of each tile are connected by a wire.  A power source is connected to the top left corner of the plate. A lamp is connected to the bottom right corner of the plate. The lamp is on only if there is a path of wires connecting power source to lamp. In order to switch the lamp on, any number of tiles can be turned by  90° (in both directions).  In the picture above the lamp is off. If any one of the tiles in the second column from the right is turned by 90° , power source and lamp get connected, and the lamp is on.  Write a program to find out the minimal number of tiles that have to be turned by 90° to switch the lamp on.  【输入】 有多组测试数据。  第一行为测试数据组数,以下每组测试数据描述为:  第一行有两个整数 N 和 M。  在接下来的 N 行中,每行有 M 个字符。每个字符均为 ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

试求:至少要旋转多少个正方形元件才能让电源与灯泡连通,若无解则输出 NO SOLUTION。ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

Casper is designing an electronic circuit on a N×M rectangular grid plate. There are N×M square tiles that are aligned to the grid on the plate. Two (out of four) opposite corners of each tile are connected by a wire.ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

A power source is connected to the top left corner of the plate. A lamp is connected to the bottom right corner of the plate. The lamp is on only if there is a path of wires connecting power source to lamp. In order to switch the lamp on, any number of tiles can be turned byZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

90° (in both directions).ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

In the picture above the lamp is off. If any one of the tiles in the second column from the right is turned by 90° , power source and lamp get connected, and the lamp is on.ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

Write a program to find out the minimal number of tiles that have to be turned by 90° to switch the lamp on.ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

【输入】

有多组测试数据。ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

第一行为测试数据组数,以下每组测试数据描述为:ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

第一行有两个整数 N 和 M。ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

在接下来的 N 行中,每行有 M 个字符。每个字符均为 "\" 或 "/",表示正方形元件上导线的连接方向。ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

The first line of input contains two integer numbers N and M, the dimensions of the plate. In each of the following N lines there are M symbols – either  \ or / – which indicate the direction of the wire connecting the opposite vertices of the corresponding tile.ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

【输出】

每组测试数据输出描述:ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

输出共一行,若有解则输出一个整数,表示至少要旋转多少个正方形元件才能让电源与灯泡连通;若无解则输出 NO SOLUTION。ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

There must be exactly one line of output. If it is possible to switch the lamp on, this line must contain only one integer number: the minimal number of tiles that have to be turned to switch on the lamp. If it is not possible, output the string: NO SOLUTIONZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

【输入样例】

1
3 5
\\/\\
\\///
/\\\\

【输出样例】

1

【提示】

对于 40% 的数据,1≤N≤4,1≤M≤5。ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

对于所有数据,1≤N,M≤500。ZAl100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

答案解析

相关题目

【例题2】魔板 【题目描述】 在成功地发明了魔方之后,拉比克先生发明了它的二维版本,称作魔板。这是一张有8个大小相同的格子的魔板: 1 2 3 4 8 7 6 5 我们知道魔板的每一个方格都有一
【例题1】电路维修 【题目描述】 译自 BalticOI 2011 Day1 T3「Switch the Lamp On」 有一种正方形的电路元件,在它的两组相对顶点中,有一组会用导线连接起来,另一
【例题4】Addition Chains 【题目描述】 已知一个数列a0,a1……am,其中a0=1,am=n; a0<a1<a2<……<am−1<am。对于每个k(1&
靶形数独 【题目描述】 小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低。但普通的数独对他们来说都过于简单了,于是他们向Z 博士请教,Z 博士拿出了他最
素数方阵 【题目描述】 在下面的方格中,每行,每列,以及两条对角线上的数字可以看作是五位的素数。方格中的行按照从左到右的顺序组成一个素数,而列按照从上到下的顺序。两条对角线也是按照从左到右的顺序来组成
平板涂色 【题目描述】 CE数码公司开发了一种名为自动涂色机(APM)的产品。它能用预定的颜色给一块由不同尺寸且互不覆盖的矩形构成的平板涂色。 为了涂色,APM需要使用一组刷子。每个刷子涂一种不同的
埃及分数 【题目描述】 在古埃及,人们使用单位分数的和(形如1/a的, a是自然数)表示一切有理数。如:2/3=1/2+1/6,但不允许2/3=1/3+1/3,因为加数中有相同的。对于一个分数a/b,
【例题3】小木棍 【题目描述】 乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,直到每段的长都不超过50。现在,他想把小木棍拼接成原来的样子,但是却忘记了自己开始时有多少根木棍和它们的长度。给出每
生日蛋糕 【题目描述】 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的MM层生日蛋糕,每层都是一个圆柱体。设从下往上数第i(1≤i≤M)层蛋糕是半径为Ri, 高度为Hi的圆柱。当
传送带 【题目描述】 在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段。两条传送带分别为线段AB和线段CD。lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R

提示声明

  • 免责声明:本站资源均来自网络或者用户投稿,仅供用于学习和交流:如有侵权联系删除!
  • 温馨提示:本文属于积分文章,需要充值获得积分或升级VIP会员,也可在会员中心投稿获取。

猜你喜欢