2016 12 12 16 12
开始
2016 12 13 17 30 还没开打
2017 1 3 .....
一星期前貌似打完了...
如下
1 #include<iostream> 2 #include<string> 3 #include<algorithm> 4 #include<cstring> 5 using namespace std; 6 int s[10]={0,1,3,7,9}; 7 int ww[12]={}; 8 int sushu[100000]={}; 9 int ans[100000][6][6]; 10 string a[100000]; 11 int top=0; 12 int hh[6]={}; 13 int num[9][9]={}; 14 int ss=0; 15 int xx=0; 16 int m,n; 17 int dfs(int h,int w,int v); 18 int yyyy() 19 { 20 int flag=0; 21 for(int i=10000;i<=99999;i++) 22 { 23 flag=0; 24 for(int u=2;u*u<=i;u++) 25 if(i%u==0){flag=1;break;} 26 if(flag==0) 27 { 28 sushu[i]=1; 29 } 30 } 31 } 32 int lie (int w) 33 { 34 int sum=0; 35 for(int i=1;i<=5;i++) 36 { 37 sum=sum*10+num[i][w]; 38 } 39 return sum; 40 } 41 int hang(int w) 42 { 43 int sum=0; 44 for(int i=1;i<=5;i++) 45 { 46 sum+=sum*10+num[i][w]; 47 } 48 return sum; 49 } 50 void shuang(int h,int w) 51 { 52 for(int i=0;i<=9;i++) 53 { 54 if(i==0&&w==1)continue; 55 if(h==1&&i==0)continue; 56 hh[h]+=i; 57 ww[w]+=i; 58 if(h==w) 59 ss+=i; 60 if(h+w==6) 61 xx+=i; 62 num[h][w]=i; 63 dfs(h,w,i); 64 num[h][w]=-1; 65 hh[h]-=i; 66 ww[w]-=i; 67 if(h==w) 68 ss-=i; 69 if(h+w==6) 70 xx-=i; 71 } 72 return ; 73 } 74 void dan(int h,int w) 75 { 76 int i=0; 77 for(int u=1;u<=4;u++) 78 { 79 if(hh[h]+s[u]>n||ww[w]+s[u]>n) 80 { 81 break; 82 } 83 if(h==w&&ss+s[u]>n) 84 break; 85 if(h+w==6&&xx+s[u]>n) 86 break; 87 i=s[u]; 88 hh[h]+=i; 89 ww[w]+=i; 90 if(h==w) 91 ss+=i; 92 if(h+w==6) 93 xx+=i; 94 num[h][w]=i; 95 dfs(h,w,num[h][w]); 96 hh[h]-=i; 97 ww[w]-=i; 98 num[h][w]=-1; 99 if(h==w) 100 ss-=i; 101 if(h+w==6) 102 xx-=i; 103 } 104 return; 105 } 106 int mj(int h,int w,char y) 107 { 108 int sum=0; 109 if(y=='s') 110 { 111 for(int i=1;i<=5;i++) 112 { 113 sum=sum*10+num[i][w]; 114 } 115 return(sushu[sum]); 116 } 117 if(y=='h') 118 { 119 for(int i=1;i<=5;i++) 120 { 121 sum=sum*10+num[h][i]; 122 } 123 return sushu[sum]; 124 } 125 if(y=='x') 126 { 127 int a=1,b=5; 128 for(int i=1;i<=5;i++) 129 { 130 sum=sum*10+num[b][a]; 131 a++;b--; 132 } 133 return sushu[sum]; 134 } 135 if(y=='z') 136 { 137 int a=1,b=1; 138 for(int i=1;i<=5;i++) 139 { 140 sum=sum*10+num[a][b]; 141 a++; 142 b++; 143 } 144 return sushu[sum]; 145 } 146 } 147 int sj(int h,int w,char y) 148 { 149 if(y=='s') 150 { 151 int s=n-ww[w]; 152 if(s>=0&&s<=9) 153 { 154 num[h][w]=s; 155 return 1; 156 } 157 num[h][w]=-1; 158 return 0; 159 } 160 if(y=='h') 161 { 162 int s=n-hh[h]; 163 if(s>=0&&s<=9) 164 { 165 num[h][w]=s; 166 return 1; 167 } 168 num[h][w]=-1; 169 return 0; 170 } 171 if(y=='x') 172 { 173 int s=n-xx; 174 if(s>=0&&s<=9) 175 { 176 num[h][w]=s; 177 return 1; 178 } 179 num[h][w]=-1; 180 return 0; 181 } 182 if(y=='z') 183 { 184 int s=n-ss; 185 if(s>=0&&s<=9) 186 { 187 num[h][w]=s; 188 return 1; 189 } 190 num[h][w]=-1; 191 return 0; 192 } 193 } 194 void suan(int h,int w,int i) 195 { 196 hh[h]+=i; 197 ww[w]+=i; 198 if(h==w) 199 ss+=i; 200 if(h+w==6) 201 xx+=i; 202 dfs(h,w,num[h][w]); 203 hh[h]-=i; 204 ww[w]-=i; 205 num[h][w]=-1; 206 if(h==w) 207 ss-=i; 208 if(h+w==6) 209 xx-=i; 210 return ; 211 } 212 int dfs(int h,int w,int v) 213 { 214 if(hh[h]>n||ww[w]>n||xx>n||ss>n) 215 { 216 return 0; 217 } 218 if(h==1&&w==1) 219 { 220 dan(5,5);//5,5 221 } 222 if(h==5&&w==5){dan(4,5);return 0;}//(4,5); 223 if(h==4&&w==5){dan(3,5);return 0;}//3,5; 224 if(h==3&&w==5){dan(2,5);return 0;}//2,5; 225 if(h==2&&w==5){if(sj(1,5,'s')==1){if(mj(1,5,'s')==0){num[1][5]=-1;return 0;}suan(1,5,num[1][5]);return 0;}}//disuan 1 5 226 if(h==1&&w==5){dan(5,1);return 0;}//5.1; 227 if(h==5&&w==1){dan(5,2);return 0;}//5.2; 228 if(h==5&&w==2){dan(5,3);return 0;}//5.3; 229 if(h==5&&w==3){if(sj(5,4,'h')==1){if(mj(5,4,'h')==0){num[5][4]=-1;return 0;}suan(5,4,num[5][4]);}return 0;}//suan 5,4; 230 if(h==5&&w==4){shuang(4,2);return 0;} 231 if(h==4&&w==2){shuang(3,3);return 0;} 232 if(h==3&&w==3){if(sj(2,4,'x')==1){if(mj(2,4,'x')==0){num[2][4]=-1;return 0;}suan(2,4,num[2][4]);}return 0;}//suan 2 4; 233 if(h==2&&w==4){shuang(2,2);return 0;}//2 2; 234 if(h==2&&w==2){if(sj(4,4,'z')==1){if(mj(4,4,'z')==0){num[4][4]=-1;return 0;}suan(4,4,num[4][4]);}return 0;}//suan 4 4; 235 if(h==4&&w==4){shuang(1,2);return 0;}//1 2; 236 if(h==1&&w==2){if(sj(3,2,'s')==1){if(mj(3,2,'s')==0){num[3][2]=-1;return 0;}suan(3,2,num[3][2]);}return 0;}//suan 3 2; 237 if(h==3&&w==2){shuang(3,1);return 0;} 238 if(h==3&&w==1){if(sj(3,4,'h')==1){if(mj(3,4,'h')==0){num[3][4]=-1;return 0;}suan(3,4,num[3][4]);}return 0;}//suan 3,4; 239 if(h==3&&w==4){if(sj(1,4,'s')==1){if(mj(1,4,'s')==0){num[1][4]=-1;return 0;}suan(1,4,num[1][4]);}return 0;} 240 if(h==1&&w==4){if(sj(1,3,'h')==1){if(mj(1,3,'h')==0){num[1][3]=-1;return 0;}suan(1,3,num[1][3]);}return 0;} 241 if(h==1&&w==3){shuang(2,1);return 0;} 242 if(h==2&&w==1){if(sj(2,3,'h')==1){if(mj(2,3,'h')==0){num[2][3]=-1;return 0;}suan(2,3,num[2][3]);}return 0;} 243 if(h==2&&w==3){if(sj(4,1,'s')==1){if(mj(4,1,'s')==0){num[4][1]=-1;return 0;}suan(4,1,num[4][1]);}return 0;} 244 if(h==4&&w==1) 245 { 246 int t=n-hh[4]; 247 int w=n-ww[3]; 248 if(w!=t)return 0; 249 if(w<=9&&w>=0) 250 if(w==t) 251 { 252 num[4][3]=w; 253 if(mj(4,3,'s')==1&&mj(4,3,'h')==1) 254 { 255 top++; 256 for(int i=1;i<=5;i++) 257 { 258 for(int u=1;u<=5;u++) 259 ans[top][i][u]=num[i][u]; 260 } 261 num[4][3]=0; 262 } 263 } 264 return 0; 265 } 266 return 0; 267 } 268 int main() 269 { yyyy(); 270 //freopen("a.in","r",stdin); 271 //freopen("a.out","w",stdout); 272 memset(num,-1,sizeof(num)); 273 cin>>n>>m; 274 num[1][1]=m; 275 hh[1]=m; 276 ww[1]=m; 277 ss=m; 278 dfs(1,1,m); 279 for(int i=1;i<=top;i++) 280 { 281 for(int u=1;u<=5;u++) 282 for(int w=1;w<=5;w++) 283 a[i]+=char(ans[i][u][w]+'0'); 284 } 285 sort(a+1,a+top+1);int w=0; 286 for(int i=1;i<=top;i++) 287 { 288 w++; 289 for(int w=0;w<a[i].size();w++) 290 { 291 cout<<a[i][w]; 292 if((w+1)%5==0)cout<<endl; 293 } 294 cout<<endl; 295 } 296 return 0; 297 }
//感觉跟lanshen比弱的一批QAQ;
药丸QAQ;