进制构造 这里用了十进制 有点像串并联 每一位代表的数分开表示出来再把每一位的数并起来 比如892 就是800+90+2 800又可分为8*10*10。。。
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<queue> 8 #include<stack> 9 using namespace std; 10 int w[1010][1010],s[20],en[20]; 11 int a[20]; 12 int main() 13 { 14 int k,i,j; 15 cin>>k; 16 int g = 0; 17 while(k) 18 { 19 a[++g] = k%10; 20 k/=10; 21 } 22 int o = 2; 23 int t; 24 for(i = 1 ; i <= g ; i++) 25 { 26 if(!a[i]) continue; 27 o++; 28 w[1][o] = w[o][1] = 1; 29 for(j = 1 ; j < 10-i ; j++) 30 { 31 w[o][o+1] = w[o+1][o] = 1; 32 o++; 33 } 34 for(j = 1; j <= a[i] ; j++) 35 w[o][o+j] = w[o+j][o] = 1; 36 t = o+a[i]; 37 for(j = 1 ; j < i ; j++) 38 { 39 for(int k = o+1 ; k <= t ; k ++) 40 { 41 for(int e = t+1 ; e <= t+10 ; e++) 42 w[k][e] = w[e][k] = 1; 43 o = t; 44 } 45 t+=10; 46 } 47 for(j = o+1 ; j <= t ; j++) 48 w[j][t+1] = w[t+1][j] = 1; 49 o = t+1; 50 w[o][2] = w[2][o] = 1; 51 } 52 cout<<o<<endl; 53 for(i = 1; i <= o ; i++) 54 { 55 for(j = 1; j <= o ; j++) 56 if(w[i][j]) 57 cout<<"Y"; 58 else 59 cout<<"N"; 60 puts(""); 61 } 62 return 0; 63 }