2014
01-05

# Switches

There are N lamps in a line and M switches control them. Each switch is connected to a subset of these lamps. When a switch is flipped, all the lamps connected to it change its state (on to off and off to on).

The input contains multiple test cases. Each test case starts with two integers N and M (0<N<=50, 0<M<=100), which stand for the number of lamps and swithes. Then M lines follows, each line contains N characters. The jth character of the ith line is ’1′ if the ith switch is connected to the jth lamp, and ’0′ otherwise. The next line is a integer Q, which is the number of queries. Each of following Q lines contains the initial and target state of lamps (’0′ is off and ’1′ is on).

The input contains multiple test cases. Each test case starts with two integers N and M (0<N<=50, 0<M<=100), which stand for the number of lamps and swithes. Then M lines follows, each line contains N characters. The jth character of the ith line is ’1′ if the ith switch is connected to the jth lamp, and ’0′ otherwise. The next line is a integer Q, which is the number of queries. Each of following Q lines contains the initial and target state of lamps (’0′ is off and ’1′ is on).

5 3
00000
10101
01010
3
00000 11111
10101 01010
11111 10001

Yes
Yes
No

1. L（X [0 .. M-1]，Y [0 .. N-1]）= 1 + L（X [0 .. M-2]，Y [0 .. N-1]）这个地方也也有笔误
应改为L（X [0 .. M-1]，Y [0 .. N-1]）= 1 + L（X [0 .. M-2]，Y [0 .. N-2]）

2. 第二个方法挺不错。NewHead代表新的头节点，通过递归找到最后一个节点之后，就把这个节点赋给NewHead，然后一直返回返回，中途这个值是没有变化的，一边返回一边把相应的指针方向颠倒，最后结束时返回新的头节点到主函数。

3. [email protected]