Description
Xiao Ming was kidnapped by the wizard W of Planet X.
At the time, W is toying with two sets of data (2 3 5 8) and (1 4 6 7)
He ordered Xiaoming to match the number from one set of data to the numbers in the other, 4 pairs (each number in the group must be used).
Xiao Ming's Matching method is: {(8,7), (5,6), (3,4), (2,1)}
The sorcerer stared for a moment, and suddenly said the match was wonderful.
Because: the number in each pairing consists of two digits, squared sum, whether it is inverted, incredibly equal: 87^2 + 56^2 + 34^2 + 21^2 = 12302
78^2 + 65^2 + 43^2 + 12^2 = 12302
Xiao Ming thought to say: "This is what is strange, we all the Earth people know, casually match also can ah." "{(8,6), (5,4), (3,1), (2,7)}
86^2 + 54^2 + 31^2 + 27^2 = 12002 68^2 + 45^2 + 13^2 + 72^2 = 12002
The wizard was suddenly messy ...
Please calculate, including the two methods given above, wizards of the two sets of data on how many kinds of pairing scheme has this feature. Pairing scenarios are counted regardless of the order in which they appear. So:
{(8,7), (5,6), (3,4), (2,1)} with {(5,6), (8,7), (3,4), (2,1)} is the same scenario.
Note: You need to submit an integer, do not fill in any superfluous content (for example, explain the text, etc.) ideas
Directly enumerate all cases, DFS can, the final answer is: code
#include <bits/stdc++.h> using namespace std; int a[]= {2,3,5,8}; int b[]= {1,4,6,7}; int n
UM[4][2],ANS=0,VIS[10];
void Dfs (int r[][2],int d) {if (d>=4) {int x=0,y=0;
for (int i=0; i<4; i++) {x+=r[i][0]*r[i][0];
Y+=R[I][1]*R[I][1];
} if (x==y) {ans++;
Return
}} for (int i=0, i<4; i++) for (int j=0; j<4; J + +) {if (!vis[i]) {
R[I][0]=A[I]*10+B[J];
R[i][1]=b[i]*10+a[i];
Vis[i]=1;
DFS (R,D+1);
vis[i]=0;
}}} int main () {DFS (num,0);
printf ("%d\n", ans);
return 0; }