这题用了一个优化避免了大数运算。宽搜只搜0和1,找能整除n的只有0,1的十进制数。所以只要mod就可以了,然后就可以把每一个点的模都求出来,然后再*10+1或者*10+0存起来,如果能整除n的话,返回,否则继续找。反正大体上就是这个思路。然后直接提交就超时了,然后我就打了表。
1 #include <string> 2 #include <iostream> 3 #include <queue> 4 using namespace std; 5 6 struct node 7 { 8 string temp; 9 int rem; 10 }; 11 int n; 12 string bfs(node a) 13 { 14 node t,t1,t2; 15 int i,j; 16 queue<node>haha; 17 haha.push(a); 18 while(haha.size()>0) 19 { 20 //cout<<"t.temp="<<t.temp<<endl; 21 t=haha.front(); 22 haha.pop(); 23 t1.temp=t.temp+"0"; 24 t1.rem=t.rem*10%n; 25 haha.push(t1); 26 if(t1.rem==0) 27 return t1.temp; 28 t2.temp=t.temp+"1"; 29 t2.rem=(t.rem*10+1)%n; 30 haha.push(t2); 31 if(t2.rem==0) 32 return t2.temp; 33 } 34 return "-1"; 35 } 36 int main() 37 { 38 string output[200+10]; 39 int tttt; 40 for(int i=1;i<=200;++i) 41 { 42 node tt; 43 tt.temp="1"; 44 tt.rem=1%i; 45 n=i; 46 output[i]=bfs(tt); 47 cout<<"\""<<output[i]<<"\","<<endl; 48 } 49 return 0; 50 } 51 52 53 54
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 string abc[200]= 5 { 6 "10", 7 "10", 8 "111", 9 "100", 10 "10", 11 "1110", 12 "1001", 13 "1000", 14 "111111111", 15 "10", 16 "11", 17 "11100", 18 "1001", 19 "10010", 20 "1110", 21 "10000", 22 "11101", 23 "1111111110", 24 "11001", 25 "100", 26 "10101", 27 "110", 28 "110101", 29 "111000", 30 "100", 31 "10010", 32 "1101111111", 33 "100100", 34 "1101101", 35 "1110", 36 "111011", 37 "100000", 38 "111111", 39 "111010", 40 "10010", 41 "11111111100", 42 "111", 43 "110010", 44 "10101", 45 "1000", 46 "11111", 47 "101010", 48 "1101101", 49 "1100", 50 "1111111110", 51 "1101010", 52 "10011", 53 "1110000", 54 "1100001", 55 "100", 56 "100011", 57 "100100", 58 "100011", 59 "11011111110", 60 "110", 61 "1001000", 62 "11001", 63 "11011010", 64 "11011111", 65 "11100", 66 "100101", 67 "1110110", 68 "1111011111", 69 "1000000", 70 "10010", 71 "1111110", 72 "1101011", 73 "1110100", 74 "10000101", 75 "10010", 76 "10011", 77 "111111111000", 78 "10001", 79 "1110", 80 "11100", 81 "1100100", 82 "1001", 83 "101010", 84 "10010011", 85 "10000", 86 "1111111101", 87 "111110", 88 "101011", 89 "1010100", 90 "111010", 91 "11011010", 92 "11010111", 93 "11000", 94 "11010101", 95 "1111111110", 96 "1001", 97 "11010100", 98 "10000011", 99 "100110", 100 "110010", 101 "11100000", 102 "11100001", 103 "11000010", 104 "111111111111111111", 105 "100", 106 "101", 107 "1000110", 108 "11100001", 109 "1001000", 110 "101010", 111 "1000110", 112 "100010011", 113 "110111111100", 114 "1001010111", 115 "110", 116 "111", 117 "10010000", 118 "1011011", 119 "110010", 120 "1101010", 121 "110110100", 122 "10101111111", 123 "110111110", 124 "100111011", 125 "111000", 126 "11011", 127 "1001010", 128 "10001100111", 129 "11101100", 130 "1000", 131 "11110111110", 132 "11010011", 133 "10000000", 134 "100100001", 135 "10010", 136 "101001", 137 "11111100", 138 "11101111", 139 "11010110", 140 "11011111110", 141 "11101000", 142 "10001", 143 "100001010", 144 "110110101", 145 "100100", 146 "10011", 147 "100110", 148 "1001", 149 "1111111110000", 150 "11011010", 151 "100010", 152 "1100001", 153 "11100", 154 "110111", 155 "11100", 156 "1110001", 157 "11001000", 158 "10111110111", 159 "10010", 160 "1110110", 161 "1010100", 162 "10101101011", 163 "100100110", 164 "100011", 165 "100000", 166 "11101111", 167 "11111111010", 168 "1010111", 169 "1111100", 170 "1111110", 171 "1010110", 172 "11111011", 173 "10101000", 174 "10111101", 175 "111010", 176 "1111011111", 177 "110110100", 178 "1011001101", 179 "110101110", 180 "100100", 181 "110000", 182 "100101111", 183 "110101010", 184 "11010111", 185 "11111111100", 186 "1001111", 187 "10010", 188 "100101", 189 "110101000", 190 "1110", 191 "100000110", 192 "1001011", 193 "1001100", 194 "1010111010111", 195 "110010", 196 "11101111", 197 "111000000", 198 "11001", 199 "111000010", 200 "101010", 201 "110000100", 202 "1101000101", 203 "1111111111111111110", 204 "111000011", 205 "1000" 206 }; 207 int main() 208 { 209 int n; 210 while(cin>>n&&n) 211 { 212 n--; 213 cout<<abc[n]<<endl; 214 } 215 return 0; 216 }