mathe 发表于 2014-12-16 13:03:52
编程20分钟,运行8分9秒,总共32个解mathe 发表于 2014-12-16 13:09:05
#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={6,5,4,3,2,1}; static unsigned char used; static int ruler_to_search; static int len_to_search; static int searched_len; 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;j++){ printf("% 2d ",searched_len); } printf("\n"); } }void search_next() { int i,j; int prev_len=0; if(len_to_search==num_lens){ 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; } for(i=prev_len+1;i<=TOTAL_STATES;++i){ if(used)continue; for(j=0;j<len_to_search;j++){ if(used])break; } if(j<len_to_search)continue; //find a candidate searched_len=i; used=1; for(j=0;j<len_to_search;j++){ used]=1; } len_to_search++; search_next(); len_to_search--; if(len_to_search<0){ ruler_to_search--; len_to_search=num_lens-1; } used=0; for(j=0;j<len_to_search;j++){ used]=0; } } }int main() { search_next(); printf("Total %d solutions found\n",count); }mathe 发表于 2014-12-16 13:11:15
Solution 1: 1530365053 818344655 2244356 74051 1542 39 Solution 2: 1530365053 818344655 2244356 74051 2742 39 Solution 3: 1530365053 818344655 2244356 114451 1542 39 Solution 4: 1530365053 818344655 2244356 114451 2742 39 Solution 5: 1530365053 818344655 13325456 74051 1542 39 Solution 6: 1530365053 818344655 13325456 74051 2742 39 Solution 7: 1530365053 818344655 13325456 114451 1542 39 Solution 8: 1530365053 818344655 13325456 114451 2742 39 Solution 9: 1530365053 921374755 2244356 74051 1542 39 Solution 10: 1530365053 921374755 2244356 74051 2742 39 Solution 11: 1530365053 921374755 2244356 114451 1542 39 Solution 12: 1530365053 921374755 2244356 114451 2742 39 Solution 13: 1530365053 921374755 13325456 74051 1542 39 Solution 14: 1530365053 921374755 13325456 74051 2742 39 Solution 15: 1530365053 921374755 13325456 114451 1542 39 Solution 16: 1530365053 921374755 13325456 114451 2742 39 Solution 17: 31723485253 818344655 2244356 74051 1542 39 Solution 18: 31723485253 818344655 2244356 74051 2742 39 Solution 19: 31723485253 818344655 2244356 114451 1542 39 Solution 20: 31723485253 818344655 2244356 114451 2742 39 Solution 21: 31723485253 818344655 13325456 74051 1542 39 Solution 22: 31723485253 818344655 13325456 74051 2742 39 Solution 23: 31723485253 818344655 13325456 114451 1542 39 Solution 24: 31723485253 818344655 13325456 114451 2742 39 Solution 25: 31723485253 921374755 2244356 74051 1542 39 Solution 26: 31723485253 921374755 2244356 74051 2742 39 Solution 27: 31723485253 921374755 2244356 114451 1542 39 Solution 28: 31723485253 921374755 2244356 114451 2742 39 Solution 29: 31723485253 921374755 13325456 74051 1542 39 Solution 30: 31723485253 921374755 13325456 74051 2742 39 Solution 31: 31723485253 921374755 13325456 114451 1542 39 Solution 32: 31723485253 921374755 13325456 114451 2742 39 Total 32 solutions foundzeroieme 发表于 2014-12-16 14:21:07
mathe 发表于 2014-12-16 12:49解不唯一
对称性!
如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$ 种组合。
zeroieme 发表于 2014-12-16 14:24:05
我还在算,不过我加入了消对称代码出来了
1 4 25 6 14 3
8 10 16 12 9
2 22 19 13
7 33 11
15 27
39
毒酒滴冻鸭 发表于 2014-12-16 14:48:13
这里大神果然很多。。。这道题算是一个不错的编程习作吧。。。手上还有几个很需要编程高手功力的数学趣题,有空提出研究!mathe 发表于 2014-12-16 15:09:54
消除对称时间可以减少到两分多。如果每个尺子的表示中首段小于尾段,时间将近3分钟,如果改成将最靠近中间两刻度消除对称情况,时间可缩减到略大于2分gxqcn 发表于 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
这是一楼的图配上各段长度标识,跟15#的数据一致。