编程介的小学生 2018-11-29 17:04 采纳率: 20.5%
浏览 354
已采纳

这个问题用C语言怎么进行解答?

Problem Description
The ninja Ryu has infiltrated the Shadow Clan fortress and finds himself in a long hallway. Although ninjas are excellent fighters, they primarily rely on stealth to complete their missions. However, many lights are turned on in the hallway, and this way it will not take long before Ryu is spotted by a guard. To remain unseen, Ryu will need to turn off all the lights as quickly as possible.
The hallway contains a sequence of n lights L1......Ln. Some of these lights are turned on. Destroy-ing the lights with his shurikens would be too loud, so he needs to turn them off the old-fashioned way, using light switches. Luckily, there is a switch box nearby with a light switch Si for every light Li. However, after trying one of the switches, he notices something funny. When he
ips the switch Si, it does not only turn on/off light Li, but also some of the neighboring lights. Ryu notices that there is a parameter D such that
ipping switch Si turns on/off all the lights L(i-D)......L(i+D), if they exist(This means that S1 turns on/off all the lights L1 ......L(D+1) and Sn turns on/off all the lights L(n-D)......Ln. Of course, if D>=n, then L(D+1) and L(n-D) will not exist either.). Turning on or off lights can attract the attention of the guards, so Ryu would like to turn off all the lights with the minimum number of times
ipping a switch. Can you help him out?

Input
The first line of the input contains a single number: the number of test cases to follow. Each test case has the following format:
1.One line with two integers n (1 <= n <= 100) and D (0 <= D <= 15): the number of lights and the parameter mentioned above.
2.One line with n integers. The i(th) integer describes the current state of light Li, where 0 means off and 1 means on.

Output
For every test case in the input, the output should contain one integer on a single line: the minimum number of times Ryu needs to flip a switch to turn off all the lights. If it is impossible to turn off all the lights, then output the string "impossible" instead.
In the first example below,flipping switch S4 followed by S7 will turn off all the lights.

Sample Input
2
7 3
1 1 1 0 0 0 0
5 1
1 0 1 0 1

Sample Output
2
3

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-02-16 23:35
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名