编程介的小学生 2019-05-07 16:18 采纳率: 20.5%
浏览 130

开关的组合的变换的一个算法问题,怎么利用C程序的语言的代码的编写实现的?

Problem Description
There are several switches and lamps in the room, however, the connections between them are very complicated. One lamp may be controlled by several switches, and one switch may controls at most two lamps. And what’s more, some connections are reversed by mistake, so it’s possible that some lamp is lighted when its corresponding switch is “OFF”!

To make things easier, we number all the lamps from 1 to N, and all the switches 1 to M. For each lamps, we give a list of switches controlling it. For example, for Lamp 1, the list is “1 ON 3 OFF 9 ON”, that means Lamp 1 will be lighted if the Switch 1 is at the “ON” state OR the Switch 3 is “OFF” OR the Switch 9 is “ON”.

Now you are requested to turn on or off the switches to make all the lamps lighted.

Input
There are several test cases in the input. The first line of each test case contains N and M (1 <= N,M <= 500), then N lines follow, each indicating one lamp. Each line begins with a number K, indicating the number of switches controlling this lamp, then K pairs of “x ON” or “x OFF” follow.

Output
Output one line for each test case, each contains M strings “ON” or “OFF”, indicating the corresponding state of the switches. For the solution may be not unique, any correct answer will be OK. If there are no solutions, output “-1” instead.

Sample Input
2 2
2 1 ON 2 ON
1 1 OFF
2 1
1 1 ON
1 1 OFF

Sample Output
OFF ON
-1

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看