找回密码
 欢迎注册
楼主: 毒酒滴冻鸭

[讨论] 织女的六把黄金尺子问题

[复制链接]
发表于 2014-12-16 13:03:52 来自手机 | 显示全部楼层
编程20分钟,运行8分9秒,总共32个解

点评

请问有把左右镜像剔除吗?  发表于 2014-12-16 14:15

评分

参与人数 1威望 +5 金币 +1 贡献 +5 经验 +5 鲜花 +5 收起 理由
liangbch + 5 + 1 + 5 + 5 + 5 很给力,我自愧不如。mathe不在乎钱。故只.

查看全部评分

毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2014-12-16 13:09:05 来自手机 | 显示全部楼层
  1. #include <stdio.h> #include <stdlib.h> #include <string.h> #define NUM_RULES 6 #define MAX_LENS_COUNT 6 #define TOTAL_STATES 56 static const int num_lens[NUM_RULES]={6,5,4,3,2,1}; static unsigned char used[TOTAL_STATES+1]; static int ruler_to_search; static int len_to_search; static int searched_len[NUM_RULES][MAX_LENS_COUNT]; static int count;  void output_result() {     int i,j;     printf("Solution %d:\n",++count);     for(i=0;i<NUM_RULES;i++){         printf("\t");         for(j=0;j<num_lens[i];j++){            printf("% 2d ",searched_len[i][j]);         }         printf("\n");     } }  void search_next() {     int i,j;     int prev_len=0;     if(len_to_search==num_lens[ruler_to_search]){         ruler_to_search++;len_to_search=0;         if(ruler_to_search==NUM_RULES){             output_result();             return;         }     }     if(len_to_search>0){        prev_len=searched_len[ruler_to_search][len_to_search-1];     }     for(i=prev_len+1;i<=TOTAL_STATES;++i){        if(used[i])continue;        for(j=0;j<len_to_search;j++){             if(used[i-searched_len[ruler_to_search][j]])break;        }        if(j<len_to_search)continue;        //find a candidate        searched_len[ruler_to_search][len_to_search]=i;        used[i]=1;        for(j=0;j<len_to_search;j++){             used[i-searched_len[ruler_to_search][j]]=1;        }        len_to_search++;        search_next();        len_to_search--;        if(len_to_search<0){             ruler_to_search--;             len_to_search=num_lens[ruler_to_search]-1;        }        used[i]=0;        for(j=0;j<len_to_search;j++){             used[i-searched_len[ruler_to_search][j]]=0;        }     } }  int main() {     search_next();     printf("Total %d solutions found\n",count); }
复制代码

点评

mathe 果然厉害  发表于 2014-12-16 19:27
非常简洁有力的C代码!  发表于 2014-12-16 14:52
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2014-12-16 13:11:15 来自手机 | 显示全部楼层
Solution 1:          1  5  30  36  50  53          8  18  34  46  55          2  24  43  56          7  40  51          15  42          39 Solution 2:          1  5  30  36  50  53          8  18  34  46  55          2  24  43  56          7  40  51          27  42          39 Solution 3:          1  5  30  36  50  53          8  18  34  46  55          2  24  43  56          11  44  51          15  42          39 Solution 4:          1  5  30  36  50  53          8  18  34  46  55          2  24  43  56          11  44  51          27  42          39 Solution 5:          1  5  30  36  50  53          8  18  34  46  55          13  32  54  56          7  40  51          15  42          39 Solution 6:          1  5  30  36  50  53          8  18  34  46  55          13  32  54  56          7  40  51          27  42          39 Solution 7:          1  5  30  36  50  53          8  18  34  46  55          13  32  54  56          11  44  51          15  42          39 Solution 8:          1  5  30  36  50  53          8  18  34  46  55          13  32  54  56          11  44  51          27  42          39 Solution 9:          1  5  30  36  50  53          9  21  37  47  55          2  24  43  56          7  40  51          15  42          39 Solution 10:          1  5  30  36  50  53          9  21  37  47  55          2  24  43  56          7  40  51          27  42          39 Solution 11:          1  5  30  36  50  53          9  21  37  47  55          2  24  43  56          11  44  51          15  42          39 Solution 12:          1  5  30  36  50  53          9  21  37  47  55          2  24  43  56          11  44  51          27  42          39 Solution 13:          1  5  30  36  50  53          9  21  37  47  55          13  32  54  56          7  40  51          15  42          39 Solution 14:          1  5  30  36  50  53          9  21  37  47  55          13  32  54  56          7  40  51          27  42          39 Solution 15:          1  5  30  36  50  53          9  21  37  47  55          13  32  54  56          11  44  51          15  42          39 Solution 16:          1  5  30  36  50  53          9  21  37  47  55          13  32  54  56          11  44  51          27  42          39 Solution 17:          3  17  23  48  52  53          8  18  34  46  55          2  24  43  56          7  40  51          15  42          39 Solution 18:          3  17  23  48  52  53          8  18  34  46  55          2  24  43  56          7  40  51          27  42          39 Solution 19:          3  17  23  48  52  53          8  18  34  46  55          2  24  43  56          11  44  51          15  42          39 Solution 20:          3  17  23  48  52  53          8  18  34  46  55          2  24  43  56          11  44  51          27  42          39 Solution 21:          3  17  23  48  52  53          8  18  34  46  55          13  32  54  56          7  40  51          15  42          39 Solution 22:          3  17  23  48  52  53          8  18  34  46  55          13  32  54  56          7  40  51          27  42          39 Solution 23:          3  17  23  48  52  53          8  18  34  46  55          13  32  54  56          11  44  51          15  42          39 Solution 24:          3  17  23  48  52  53          8  18  34  46  55          13  32  54  56          11  44  51          27  42          39 Solution 25:          3  17  23  48  52  53          9  21  37  47  55          2  24  43  56          7  40  51          15  42          39 Solution 26:          3  17  23  48  52  53          9  21  37  47  55          2  24  43  56          7  40  51          27  42          39 Solution 27:          3  17  23  48  52  53          9  21  37  47  55          2  24  43  56          11  44  51          15  42          39 Solution 28:          3  17  23  48  52  53          9  21  37  47  55          2  24  43  56          11  44  51          27  42          39 Solution 29:          3  17  23  48  52  53          9  21  37  47  55          13  32  54  56          7  40  51          15  42          39 Solution 30:          3  17  23  48  52  53          9  21  37  47  55          13  32  54  56          7  40  51          27  42          39 Solution 31:          3  17  23  48  52  53          9  21  37  47  55          13  32  54  56          11  44  51          15  42          39 Solution 32:          3  17  23  48  52  53          9  21  37  47  55          13  32  54  56          11  44  51          27  42          39 Total 32 solutions found
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2014-12-16 14:21:07 | 显示全部楼层


对称性!
如1号尺
1 5 30 36 50 53 转为差分形式  1 4 25 6 14 3
3 17 23 48 52 53 转为差分形式  3 14 6 25 4 1

6把尺子的一个解,正反表示,有$2^5=32$ 种组合。
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2014-12-16 14:24:05 | 显示全部楼层
我还在算,不过我加入了消对称代码

出来了
  1. 1 4 25 6 14 3
  2. 8 10 16 12 9
  3. 2 22 19 13
  4. 7 33 11
  5. 15 27
  6. 39
复制代码

点评

如果可以的话不妨穷搜一下其它数量的尺子:五尺子量1..35、四尺子量1..20、三尺子量1..10、二尺子量1..4。。。七尺子量1..84这个应该无解,但很花时间验证。。。  发表于 2014-12-16 14:44
很好,跟1楼图片的数据相同。。。希望能完整搜寻,然后记录总用时。。。  发表于 2014-12-16 14:41
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2014-12-16 14:48:13 | 显示全部楼层
这里大神果然很多。。。这道题算是一个不错的编程习作吧。。。手上还有几个很需要编程高手功力的数学趣题,有空提出研究!
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2014-12-16 15:09:54 来自手机 | 显示全部楼层
消除对称时间可以减少到两分多。如果每个尺子的表示中首段小于尾段,时间将近3分钟,如果改成将最靠近中间两刻度消除对称情况,时间可缩减到略大于2分
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2014-12-16 15:44:22 | 显示全部楼层
如果略作修改,要求测量连续整数的区间跨度尽可能大,答案是否还是一样?会不会更复杂?
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2014-12-16 19:41:54 | 显示全部楼层
mathe 发表于 2014-12-16 15:09
消除对称时间可以减少到两分多。如果每个尺子的表示中首段小于尾段,时间将近3分钟,如果改 ...


这是用中科院级的超级电脑运算还是一般的个人电脑?
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2014-12-16 19:43:39 | 显示全部楼层
rulers6.png

这是一楼的图配上各段长度标识,跟15#的数据一致。
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

小黑屋|手机版|数学研发网 ( 苏ICP备07505100号 )

GMT+8, 2024-4-27 13:08 , Processed in 0.055182 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表