代码
#include<bits/stdc++.h>
using namespace std;
int p[10],w[10];
int cnt;
int find(int x)
{
if(p[x]!=x)p[x]=find(p[x]);
return p[x];
}
void turn(int x)
{
if(x==1)
{
if(w[2])p[find(2)]=p[find(x)];
if(w[7])p[find(7)]=p[find(x)];
}
if(x==2)
{
if(w[1])p[find(1)]=p[find(x)];
if(w[3])p[find(3)]=p[find(x)];
if(w[4])p[find(4)]=p[find(x)];
}
if(x==3)
{
if(w[4])p[find(4)]=p[find(x)];
if(w[2])p[find(2)]=p[find(x)];
if(w[7])p[find(7)]=p[find(x)];
if(w[6])p[find(6)]=p[find(x)];
}
if(x==4)
{
if(w[2])p[find(2)]=p[find(x)];
if(w[3])p[find(3)]=p[find(x)];
if(w[5])p[find(5)]=p[find(x)];
}
if(x==5)
{
if(w[4])p[find(4)]=p[find(x)];
if(w[6])p[find(6)]=p[find(x)];
}
if(x==6)
{
if(w[7])p[find(7)]=p[find(x)];
if(w[3])p[find(3)]=p[find(x)];
if(w[5])p[find(5)]=p[find(x)];
}
if(x==7)
{
if(w[1])p[find(1)]=p[find(x)];
if(w[3])p[find(3)]=p[find(x)];
if(w[6])p[find(6)]=p[find(x)];
}
}
int main()
{
for(int i=0;i<128;i++)
{
for(int i=1;i<=7;i++)
{
p[i]=i;
w[i]=0;
}
for(int j=0;j<7;j++)
{
if(i>>j&1)
{
turn(j+1);
w[j+1]=1;
}
}
int temp=0;
for(int i=1;i<=7;i++)if(p[i]==i&&w[i]==1)temp++;
if(temp==1)cnt++;
}
cout<<cnt;
return 0;
}
-------------------------------------------------------选自第十一届蓝桥杯A/B组填空题第四题七段码