POJ 1222:extended LIGHTS out

Source: Internet
Author: User

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 8417 Accepted: 5441

Description

in an extended version of the game Lights out, was a puzzle with 5 rows of 6 buttons each (the actual puzzle have 5 rows of 5 buttons each). Each button is a light. When a button is pressed, then button and each of it (up to four) neighbors above, below, right and left, have the state O F its light reversed. (If on, the light was turned off; if off, the light was turned on.) Buttons in the corners and the state of 3 Buttons; Buttons on a edge change the state of 4 buttons and other buttons the state of 5. For example, if the buttons marked X in the left below were to is pressed,the display would change to the image on the rig Ht.

The aim of the game is, starting from any initial set of lights on the display, to press buttons to get the display To a, the where all lights is off. When adjacent buttons is pressed, the action of one button can undo the effect of another. For instance, in the display below, pressing buttons marked X on the left display results in the right display. Note that the buttons in row 2 column 3 and row 2 column 5 both change the state of the button in row 2 column 4,so that, In the end, it is unchanged.

Note:
1. It does not matter what order the buttons is pressed.
2. If a button is pressed a second time, it exactly cancels the effect of the first press, so no button ever need be P Ressed more than once.
3. As illustrated in the second diagram, all the lights in the first row is turned off, by pressing the correspond ing buttons in the second row. By repeating this process in each row, all the lights in the first
Four rows is turned out. Similarly, by pressing buttons in columns 2, 3?, all lights in the first 5 columns could be turned off.
Write A program to solve the puzzle.

Input

The first line of the input is a positive integer n which are the number of puzzles that follow. Each puzzle is five lines, each of the which have six 0 or 1 separated by one or more spaces. A 0 indicates that's the light is off and while a 1 indicates that's on initially.

Output

for each puzzle, the output consists of a line with the string: "Puzzle #m", where M was the index of the puzzle in the Input file. Following a puzzle-like display (in the same format as the input). In this case, 1 ' s indicate buttons that must is pressed to solve the puzzle, while 0 indicate buttons, which is not press Ed. There should is exactly one space between each 0 or 1 in the output puzzle-like display.

Sample Input

20 1 1 0 1 01 0 0 1 1 10 0 1 0 0 11 0 0 1 0 10 1 1 1 0 00 0 1 0 1 01 0 1 0 1 10 0 1 0 1 11 0 1 1 0 00 1 0 1 0 0

Sample Output

PUZZLE #11 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 0 0 0 1 1 11 1 0 0 0 00 0 0 1 0 01 1 1 0 1

Source

Greater New York 2002 The following:    give each position the lamp number 1~30, construct a 30*31 01 matrix a,a[i][j]=1 meaning is the first light bulb at the press of the switch, will affect the J bulb, if no effect is 0. If the first matrix is open, then a[i][31]=1. The 31st column of the matrix is the inverse Gaussian elimination of this matrix. detailed
1#include <iostream>2#include <cstdlib>3#include <cstdio>4#include <cmath>5#include <algorithm>6#include <vector>7#include <queue>8 using namespacestd;9 intT;Ten inta[ -][ -]; One voidGauss () { A      for(intI=1; i<= -; i++){ -         inttmp=i; -          while(tmp<= -&&a[tmp][i]==0) tmp++; the         if(tmp> -)Continue; -         if(tmp!=i) { -              for(intj=1; j<= to; j + +) Swap (a[i][j],a[tmp][j]); -         } +          for(intj=1; j<= -; j + +){ -             if(i!=j&&a[j][i]==1){ +                  for(intk=1; k<= to; k++){ Aa[j][k]^=A[i][k]; at                 } -             } -         } -     } - } - intMain () { inscanf"%d",&T); -      for(intcas=1; cas<=t; cas++){ toMemset (A,0,sizeof(a)); +          for(intI=1; i<=5; i++){ -              for(intj=1; j<=6; j + +){ the                 intnum= (I-1)*6+J; *                 intnum1=num-6, num2=num+1, num3=num+6, num4=num-1; $a[num][num]=1;Panax Notoginseng                 if(1<=num1&&num1<= -) a[num][num1]=1; -                 if(1<=num2&&num2<= -&&j!=6) a[num][num2]=1; the                 if(1<=num3&&num3<= -) a[num][num3]=1; +                 if(1<=num4&&num4<= -&&j!=1) a[num][num4]=1; A             } the         } +          for(intI=1; i<= -; i++) scanf ("%d", &a[i][ to]); - Gauss (); $printf"PUZZLE #%d\n", Cas); $          for(intI=1; i<= -; i++){ -printf"%d", a[i][ to]); -             if(i%6==0) printf ("\ n"); the         } -     }Wuyi     return 0; the}

POJ 1222:extended LIGHTS out

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.