Switching problems
| Time Limit: 1000MS |
|
Memory Limit: 30000K |
| Total Submissions: 6455 |
|
Accepted: 2463 |
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 marks
Sample 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]This to the topic is the typical application of the Gaussian elimination method. The relationship between all switches is treated as a factor, while the operation on the switch acts as a variable. In this way, the coefficient matrix and the variable matrix are formed. It is important to note that the values in each row of the coefficient matrix A[i][j] Indicate whether J has an effect on I. Code:
- HOME
- Problem
- STATUS
- CONTEST
- LOGOUT
- Zfy11
Zfy11 ' s source code for B
| Memory: 148 KB |
|
Time : 0 MS |
| Language: C++ |
|
Result: Accepted |
| Public: |
|
NoYes |
Select All
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 6667686970717273747576777879808182838485868788899091929394
#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#include<vector>#include<map>#include<iostream>UsingNamespace Std;Constint MAXN=60;int a[MAXN][maxn];int x[MAXN];int free_x[MAXN];IntGauss(int equ,int var){int IJK, Max_r, col;For(int I=0; I<=var; I++){x[I]=0; Free_x[I]=1;} col=0;For(k=0; k<equ&&col<var; k++,col++){Max_r=k;For(I=k+1; I<equ; I++){If(Abs(A[I][col]) >Abs(A[Max_r][col])) Max_r=i;}If(Max_r!=k){For(j=k; j<var+1; j++)Swap(A[k][j],a[Max_r][j]);}If(A[k][col]==0){k--;Continue;}For(I=k+1; I<equ; I++){If(A[I][col]!=0){For(j=col; j<var+1; j+ +) A[I][j]^=a[k][j];}}}For(I=k; I<equ; I++){If(A[I][col]!=0)Return-1;}return var-K;}int start[MAXN];int end[MAXN];IntMain(){int n;int sE;int T;scanf("%d", &t);While(T--){scanf("%d", &n);For(int I=0; I<n; I++){scanf("%d", &start[I]);}For(int I=0; I<n; I++){scanf("%d", &end[I]);}Memset(A,0,sizeof(A));While(scanf("%d%d", &s, &e)){If(s==0&&e==0)Break; A[E-1][s-1]=1;}For(int I=0; I<n; I+ +) A[I][i]=1;For(int I=0; I<n; I+ +) A[I][n]=start[I]^end[I];int ans=Gauss(n,n); if (Ans==-1< Span class= "Sh-symbol" >) printf (\n "); else printf ( "%d\n" ,1< Span class= "Sh-symbol" ><<ans); return 0;< Span class= "Sh-cbracket" >
Summer Practice Diary (iii)