Language:DefaultSwitching problems
Time Limit: 1000MS |
|
Memory Limit: 30000K |
Total Submissions: 6656 |
|
Accepted: 2541 |
Description There are n the same switch, each switch is associated with some switches, each time you open or close a switch, the other switches associated with this switch will also change accordingly, that is, the status of the connected switch if the original is turned off, if it is turned on. Your goal is to make the last n switches reach a specific state after several switching operations. For any switch, a maximum of one switch operation can be performed. Your task is to calculate how many methods are available to reach the specified state. (regardless of the order of the switching operation)Input Enter the first line with a number k, indicating that the following k sets of test data are available. The format of each set of test data is as follows: First row one number N (0 < N < 29) The second row n 0 or 1 of the number, indicating the start of N switch state. The third row n 0 or 1, indicating the state of n switches after the end of the operation. The next two number I J for each line indicates that the status of the J switch will change if the I switch is operated. Each set of data ends with 0 0.
Output If there is a viable method, the total output, otherwise the output "Oh,it ' s impossible~!!" does not include quotation marksSample Input 230 0 01 1 11 21 32 12 33 13 20 030 0 01 0 11 22 10 0
Sample Output 4oh,it ' s impossible~!!
Hint Description of the first set of data: Altogether the following four methods: Operation Switch 1 Operation Switch 2 Operation Switch 3 Operating switches 1, 2, 3 (no order)
Source [email protected]
|
Chinese question ~ not translate.
The idea of solving problems: mainly the processing method of the whole matrix. Can make the a+x=b on both sides of the same or a can be. This makes it easy to get an augmented matrix.
A[I][J] is a J-lamp control I-lamp. Remember to add the situation of a[i][i], almost ignore this, of course, you can control yourself ah.
AC Code:
#include <stdio.h> #include <math.h> #include <vector> #include <queue> #include <string> #include <string.h> #include <stdlib.h> #include <iostream> #include <algorithm> #define MAXN 31using namespace Std;int equ,var;int a[maxn][maxn];int Gauss () {int col=0; int k,max_r; for (k=0;col<var&&k<equ;k++,col++) {max_r=k; for (int i=k+1;i<equ;i++) if (ABS (A[i][col]) >abs (A[max_r][col])) max_r=i; if (max_r!=k) {for (int i=col;i<=var;i++) swap (a[k][i],a[max_r][i]); } if (!a[k][col]) {k--; Continue } for (int i=k+1;i<equ;i++) if (A[i][col]) for (int j=col;j<=var;j++) a[i][j]^= A[K][J]; } for (int i=k;i<equ;i++) if (A[i][col]) return-1; return var-k;} int main () {int T; scanf ("%d", &t); while (t--) {memset (a,0,sizeof (a)); scanf ("%d", &equ); var=equ; int b; for (int i=0;i<equ;i++) {//a[i][i]=1; scanf ("%d", &b); A[i][var]=b; } for (int i=0;i<equ;i++) {scanf ("%d", &b); A[i][var]^=b; } int i,j; while (scanf ("%d%d", &i,&j), i!=0| | j!=0) {a[j-1][i-1]=1; } for (int i=0;i<equ;i++) a[i][i]=1; int Res=gauss (); if (res<0) printf ("Oh,it ' s impossible~!! \ n "); else printf ("%d\n", 1<<res); } return 0;}
Copyright NOTICE: This article is the original blogger articles, reproduced please indicate the source.
POJ switching problem 1830 "Gaussian elimination to calculate the rank of matrix"