- 注册时间
- 2007-12-27
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 40155
- 在线时间
- 小时
|
发表于 2023-9-2 15:50:12
|
显示全部楼层
代码产生穷举代码,然后大概需要运行20分钟
- #include <stdio.h>
- #include <string.h>
- typedef struct PL{
- int len;
- char *data;
- }PL;
- PL pls[]={
- {2,"1112"},
- {1,"13"},
- {4,"14151617"},
- {3,"182838"},
- {4,"19293949"},
- {3,"212231"},
- {5,"2324323334"},
- {2,"2737"},
- {2,"3536"},
- {1,"41"},
- {1,"42"},
- {3,"435253"},
- {2,"4445"},
- {2,"4656"},
- {2,"4748"},
- {1,"51"},
- {2,"5758"},
- {2,"5969"},
- {3,"616263"},
- {3,"646566"},
- {2,"6768"},
- {4,"71727374"},
- {1,"75"},
- {3,"767778"},
- {5,"7987888999"},
- {7,"81828393949596"},
- {3,"848586"},
- {1,"91"},
- {1,"92"}
- };
- #define PLSN (sizeof(pls)/sizeof(pls[0]))
- int sorder[9]={3,6,0,7,8,4,5,2,1};
- #define NUMSET (PLSN+3*9)
- __int128_t allsets[NUMSET];
- void initallsets()
- {
- int i,j;
- for(i=0;i<PLSN;i++){
- __int128_t r=0;
- for(j=0;j<pls[i].len;j++){
- int row=pls[i].data[2*j]-'1';
- int col=pls[i].data[2*j+1]-'1';
- int index=row*9+col;
- __int128_t x=1;
- x<<=index;
- r|=x;
- }
- allsets[i]=r;
- }
- for(i=0;i<9;i++){//rows
- __int128_t r=0;
- for(j=0;j<9;j++){
- __int128_t x=1;
- x<<=i*9+j;
- r|=x;
- }
- allsets[PLSN+i]=r;
- }
- for(i=0;i<9;i++){
- __int128_t r=0;
- for(j=0;j<9;j++){
- __int128_t x=1;
- x<<=i+j*9;
- r|=x;
- }
- allsets[PLSN+9+i]=r;
- }
- for(i=0;i<9;i++){
- __int128_t r=0;
- for(j=0;j<9;j++){
- __int128_t x=1;
- x<<=((i%3)*3+(j%3))*9+((i/3)*3+(j/3));
- r|=x;
- }
- allsets[PLSN+18+i]=r;
- }
- }
- int main()
- {
- FILE *f=fopen("tmpsudk.c","w");
- int i,j,k,s;
- __int128_t r=0;
- initallsets();
- fprintf(f,"#include <stdio.h>\n");
- fprintf(f,"int mset[%d];\n",(int)NUMSET);
- fprintf(f,"char blocks[81];\n");
- fprintf(f,"int isprime(int x){return (x==2||x==3||x==5||x==7||x==11||x==13||x==17||x==19||x==23||x==29||x==31||x==37||x==41);}\n");
- fprintf(f,"void output(){\n");
- fprintf(f,"int i;\n");
- fprintf(f,"for(i=0;i<81;i++){\n");
- fprintf(f,"printf("%%d,",blocks[i]);\n");
- fprintf(f,"if(i%%9==8)printf("\\n");\n");
- fprintf(f,"}\n\nprintf("\\n");fflush(stdout);\n}\n\n");
- fprintf(f,"int main()\n");
- fprintf(f,"{\n");
- fprintf(f,"int ");
- for(i=0;i<81;i++)fprintf(f,"i%d,s%d,",i,i);
- fprintf(f,"s;\n");
- for(i=0;i<9;i++){
- int bb=sorder[i];
- int brow=(bb/3)*3,bcol=(bb%3)*3;
- for(j=0;j<3;j++)for(k=0;k<3;k++){
- int bid=(brow+j)*9+(bcol+k);
- fprintf(f,"for(i%d=1;i%d<=9;i%d++){\n",bid,bid,bid);
- for(s=0;s<NUMSET;s++){
- if((allsets[s]>>bid)&1){
- fprintf(f,"if((mset[%d]>>i%d)&1)continue;\n",s,bid);
- }
- }
- fprintf(f,"blocks[%d]=i%d;\n",bid,bid);
- __int128_t x=1;x<<=bid;
- r|=x;
- for(s=0;s<PLSN;s++){
- if(((allsets[s]>>bid)&1) && (r&allsets[s])==allsets[s]){//reach the set
- fprintf(f,"s=0;\n");
- __int128_t y=1;
- int t;
- for(t=0;t<128;t++){
- if(allsets[s]&y){
- fprintf(f,"s+=blocks[%d];\n",t);
- }
- y<<=1;
- }
- fprintf(f,"if(!isprime(s))continue;\n");
- }
- }
- if(i==8&&j==2&&k==2){
- fprintf(f,"output();\n");
- }
- //set of mset
- for(s=0;s<NUMSET;s++){
- if((allsets[s]>>bid)&1){
- fprintf(f,"mset[%d]|=1<<i%d;\n",s,bid);
- }
- }
- }
- }
- for(i=8;i>=0;i--){
- int bb=sorder[i];
- int brow=(bb/3)*3,bcol=(bb%3)*3;
- for(j=2;j>=0;j--)for(k=2;k>=0;k--){
- int bid=(brow+j)*9+(bcol+k);
- for(s=0;s<NUMSET;s++){
- if((allsets[s]>>bid)&1){
- fprintf(f,"mset[%d]&=~(1<<i%d);\n",s,bid);
- }
- }
- fprintf(f,"}//i%d\n",bid);
- }
- }
- fprintf(f,"}\n");
- fclose(f);
- return 0;
- }
复制代码 |
|