fork download
  1. from itertools import product, combinations_with_replacement
  2. import time
  3. import threading
  4. from collections import defaultdict
  5. import math
  6.  
  7. # 配置参数(可根据需要修改)
  8. TARGET =20000 # 目标值
  9. BASE_VALUES = [36.5, 41.5, 59,68.5, 74, 91.5] # 基础系数列表
  10. FLUCTUATION = 1.0 # 系数波动范围
  11. MAX_SOLUTIONS = 3 # 每个组合的最大解数量
  12. SOLVER_TIMEOUT = 180 # 求解超时时间(秒)
  13. THREE_VAR_THRESHOLD = 220000 # 使用三个变量的阈值
  14. PRODUCT_RANGE_THRESHOLD = 148000 # 乘积范围限制阈值
  15. HIGH_TARGET_THRESHOLD = 260000 # 更高目标值阈值
  16. SHOW_PROGRESS = True # 是否显示进度
  17. MAX_SOLUTIONS_PER_COMB = 100 # 每个组合的最大解数量,用于提前终止
  18.  
  19. def is_valid_product(p):
  20. """检查单个乘积是否在有效范围内"""
  21. if TARGET > PRODUCT_RANGE_THRESHOLD:
  22. if TARGET > HIGH_TARGET_THRESHOLD:
  23. return p <= 115000 # 目标值超过260000时,仅限制最大值
  24. else:
  25. return 74000 <= p <= 115000 # 目标值在148000-260000之间时,使用原范围
  26. else:
  27. return True # 目标值较小时不限制乘积范围
  28.  
  29. def find_single_variable_solutions(values):
  30. """查找单个数的解(a*x = TARGET)"""
  31. solutions = []
  32. for a in values:
  33. x = TARGET / a
  34. if x.is_integer() and 1 <= x <= 10000 and is_valid_product(a * x):
  35. solutions.append((a, x))
  36. if len(solutions) >= MAX_SOLUTIONS:
  37. return solutions # 提前终止
  38. return solutions
  39.  
  40. def find_two_variable_solutions(values):
  41. """查找两个变量的解(a*x + b*y = TARGET)"""
  42. solutions = defaultdict(list)
  43.  
  44. # 生成所有可能的(a, b)组合
  45. for a in values:
  46. for b in values:
  47. if a == b: # 避免重复
  48. continue
  49.  
  50. # 计算x的有效范围
  51. min_x = max(1, math.ceil((TARGET - b * 10000) / a))
  52. max_x = min(math.floor((TARGET - 1) / a), 10000)
  53.  
  54. if max_x < min_x:
  55. continue
  56.  
  57. for x in range(min_x, max_x + 1):
  58. remainder = TARGET - a * x
  59.  
  60. # 检查remainder是否在可能的范围内
  61. if remainder < 1 or remainder > b * 10000:
  62. continue
  63.  
  64. # 检查remainder是否能被b整除
  65. if remainder % b == 0:
  66. y = remainder // b
  67. if 1 <= y <= 10000 and is_valid_product(b * y):
  68. solutions[(a, b)].append((a, x, b, y))
  69. if len(solutions[(a, b)]) >= MAX_SOLUTIONS_PER_COMB:
  70. break # 提前终止当前组合的搜索
  71.  
  72. return solutions
  73.  
  74. def find_three_variable_solutions(values):
  75. """优化的三变量求解算法"""
  76. solutions = defaultdict(list)
  77.  
  78. # 对系数进行排序,便于剪枝
  79. sorted_values = sorted(values)
  80.  
  81. # 预计算每个系数的有效范围
  82. value_ranges = {}
  83. for a in sorted_values:
  84. if TARGET > PRODUCT_RANGE_THRESHOLD:
  85. if TARGET > HIGH_TARGET_THRESHOLD:
  86. min_x = max(1, math.ceil(1 / a)) # 取消下限,最小为1
  87. max_x = min(10000, math.floor(115000 / a))
  88. else:
  89. min_x = max(1, math.ceil(74000 / a))
  90. max_x = min(10000, math.floor(115000 / a))
  91. else:
  92. min_x = 1
  93. max_x = 10000
  94. value_ranges[a] = (min_x, max_x)
  95.  
  96. total_combinations = len(sorted_values) * (len(sorted_values) - 1) * (len(sorted_values) - 2) // 6
  97. processed_combinations = 0
  98.  
  99. # 三重循环,但添加了更多剪枝条件
  100. for i, a in enumerate(sorted_values):
  101. min_x, max_x = value_ranges[a]
  102.  
  103. # 计算可能的x值数量,决定步长
  104. x_count = max_x - min_x + 1
  105. x_step = max(1, x_count // 1000) # 自适应步长
  106.  
  107. for x in range(min_x, max_x + 1, x_step):
  108. ax = a * x
  109. if not is_valid_product(ax):
  110. continue
  111.  
  112. remainder1 = TARGET - ax
  113. if TARGET > PRODUCT_RANGE_THRESHOLD:
  114. if TARGET > HIGH_TARGET_THRESHOLD:
  115. if remainder1 < 0:
  116. continue
  117. else:
  118. if remainder1 < 2 * 74000:
  119. continue
  120.  
  121. # 限制b的选择范围,避免重复组合
  122. for j in range(i + 1, len(sorted_values)):
  123. b = sorted_values[j]
  124.  
  125. if TARGET > PRODUCT_RANGE_THRESHOLD:
  126. if TARGET > HIGH_TARGET_THRESHOLD:
  127. min_y = max(1, math.ceil(1 / b)) # 取消下限,最小为1
  128. max_y = min(10000, math.floor(remainder1 / b))
  129. else:
  130. min_y = max(1, math.ceil(74000 / b))
  131. max_y = min(10000, math.floor((remainder1 - 74000) / b))
  132. else:
  133. min_y = 1
  134. max_y = math.floor(remainder1 / b)
  135.  
  136. if max_y < min_y:
  137. continue
  138.  
  139. # 计算可能的y值数量,决定步长
  140. y_count = max_y - min_y + 1
  141. y_step = max(1, y_count // 100) # 自适应步长
  142.  
  143. for y in range(min_y, max_y + 1, y_step):
  144. by = b * y
  145. if not is_valid_product(by):
  146. continue
  147.  
  148. remainder2 = remainder1 - by
  149. if TARGET > PRODUCT_RANGE_THRESHOLD:
  150. if TARGET > HIGH_TARGET_THRESHOLD:
  151. if remainder2 < 0 or remainder2 > 115000:
  152. continue
  153. else:
  154. if remainder2 < 74000 or remainder2 > 115000:
  155. continue
  156.  
  157. # 限制c的选择范围
  158. found_solution = False
  159. for k in range(j + 1, len(sorted_values)):
  160. c = sorted_values[k]
  161.  
  162. # 检查remainder2是否能被c整除
  163. if remainder2 % c != 0:
  164. continue
  165.  
  166. z = remainder2 // c
  167. if 1 <= z <= 10000 and is_valid_product(c * z):
  168. key = (a, b, c)
  169. solutions[key].append((a, x, b, y, c, z))
  170. found_solution = True
  171. if len(solutions[key]) >= MAX_SOLUTIONS_PER_COMB:
  172. break # 提前终止当前组合的搜索
  173.  
  174. # 如果找到解且达到最大数量,跳出y循环
  175. if found_solution and len(solutions[key]) >= MAX_SOLUTIONS_PER_COMB:
  176. break # 跳出y循环
  177.  
  178. # 进度显示
  179. if SHOW_PROGRESS and j % 10 == 0:
  180. print(f"\r三变量组合进度: {processed_combinations}/{total_combinations} 组", end='')
  181. processed_combinations += 1
  182.  
  183. if SHOW_PROGRESS:
  184. print(f"\r三变量组合进度: {processed_combinations}/{total_combinations} 组 - 完成")
  185.  
  186. return solutions
  187.  
  188. def find_balanced_solutions(solutions, var_count, num=2):
  189. """从所有解中筛选出最平衡的解"""
  190. if var_count == 1 or not solutions:
  191. return solutions # 单变量或无解时直接返回
  192.  
  193. # 当目标值超过220000时,不计算平衡解
  194. if TARGET > THREE_VAR_THRESHOLD:
  195. return []
  196.  
  197. # 计算解的平衡性(变量间差异最小)
  198. balanced = []
  199. for sol in solutions:
  200. vars = sol[1::2] # 提取x, y, z
  201. diff = max(vars) - min(vars)
  202. balanced.append((diff, sol))
  203.  
  204. # 按差异排序,取前num个
  205. return [s for _, s in sorted(balanced, key=lambda x: x[0])[:num]]
  206.  
  207. def find_original_solutions(solutions, balanced_solutions, num=3):
  208. """从剩余解中获取原始顺序的解"""
  209. if not solutions:
  210. return []
  211.  
  212. # 排除已在平衡解中的项
  213. remaining = [s for s in solutions if s not in balanced_solutions]
  214. return remaining[:num]
  215.  
  216. def display_solutions(solutions_dict, var_count):
  217. """优化的解显示函数"""
  218. if not solutions_dict:
  219. return
  220.  
  221. print(f"\n找到 {len(solutions_dict)} 组{var_count}变量解:")
  222.  
  223. for i, (coeffs, pair_solutions) in enumerate(sorted(solutions_dict.items()), 1):
  224. # 当目标值超过220000时,不显示平衡解
  225. if TARGET > THREE_VAR_THRESHOLD:
  226. all_display = pair_solutions[:MAX_SOLUTIONS]
  227. print_tag = "[原始解]"
  228. else:
  229. # 计算平衡解和原始解
  230. balanced = find_balanced_solutions(pair_solutions, var_count)
  231. original = find_original_solutions(pair_solutions, balanced)
  232. all_display = balanced + original
  233.  
  234. if var_count == 1:
  235. a = coeffs
  236. print(f"\n{i}. 组合: a={a} ({len(pair_solutions)} 个有效解)")
  237. elif var_count == 2:
  238. a, b = coeffs
  239. print(f"\n{i}. 组合: a={a}, b={b} ({len(pair_solutions)} 个有效解)")
  240. else: # var_count == 3
  241. a, b, c = coeffs
  242. print(f"\n{i}. 组合: a={a}, b={b}, c={c} ({len(pair_solutions)} 个有效解)")
  243.  
  244. for j, sol in enumerate(all_display, 1):
  245. if TARGET > THREE_VAR_THRESHOLD:
  246. tag = print_tag
  247. else:
  248. tag = "[平衡解]" if j <= len(balanced) else "[原始解]"
  249.  
  250. if var_count == 1:
  251. a, x = sol
  252. print(f" {j}. x={x}, a*x={a*x:.1f}, 总和={a*x:.1f} {tag}")
  253. elif var_count == 2:
  254. a, x, b, y = sol
  255. print(f" {j}. x={x}, y={y}, a*x={a*x:.1f}, b*y={b*y:.1f}, 总和={a*x + b*y:.1f} {tag}")
  256. else: # var_count == 3
  257. a, x, b, y, c, z = sol
  258. print(f" {j}. x={x}, y={y}, z={z}, "
  259. f"a*x={a*x:.1f}, b*y={b*y:.1f}, c*z={c*z:.1f}, "
  260. f"总和={a*x + b*y + c*z:.1f} {tag}")
  261.  
  262. def run_with_timeout(func, args=(), kwargs=None, timeout=SOLVER_TIMEOUT):
  263. """运行函数并设置超时限制"""
  264. if kwargs is None:
  265. kwargs = {}
  266.  
  267. result = []
  268. error = []
  269.  
  270. def wrapper():
  271. try:
  272. result.append(func(*args, **kwargs))
  273. except Exception as e:
  274. error.append(e)
  275.  
  276. thread = threading.Thread(target=wrapper)
  277. thread.daemon = True
  278. thread.start()
  279. thread.join(timeout)
  280.  
  281. if thread.is_alive():
  282. print(f"警告: {func.__name__} 超时({timeout}秒),跳过此方法")
  283. return None
  284.  
  285. if error:
  286. raise error[0]
  287.  
  288. return result[0]
  289.  
  290. def main():
  291. print(f"目标值: {TARGET}")
  292.  
  293. # 生成波动后的系数
  294. FLUCTUATED_VALUES = [round(v - FLUCTUATION, 1) for v in BASE_VALUES]
  295.  
  296. # 尝试基础系数
  297. print(f"\n==== 尝试基础系数 ====")
  298.  
  299. # 检查目标值是否超过阈值
  300. if TARGET > THREE_VAR_THRESHOLD:
  301. print(f"目标值 {TARGET} 超过阈值 {THREE_VAR_THRESHOLD},只尝试三变量解")
  302. base_solutions = {
  303. 'single': [],
  304. 'two': [],
  305. 'three': run_with_timeout(find_three_variable_solutions, args=(BASE_VALUES,))
  306. }
  307.  
  308. # 显示三变量解
  309. if base_solutions['three'] and len(base_solutions['three']) > 0:
  310. display_solutions(base_solutions['three'], 3)
  311. print(f"\n使用基础系数列表,共找到有效解")
  312. return
  313. else:
  314. print("\n基础系数三变量无解,尝试波动系数")
  315. else:
  316. # 目标值未超过阈值,按顺序尝试单、双、三变量解
  317. base_solutions = {
  318. 'single': run_with_timeout(find_single_variable_solutions, args=(BASE_VALUES,)),
  319. 'two': run_with_timeout(find_two_variable_solutions, args=(BASE_VALUES,)),
  320. 'three': []
  321. }
  322.  
  323. # 检查是否有解
  324. has_solution = False
  325.  
  326. # 显示单变量解
  327. if base_solutions['single']:
  328. has_solution = True
  329. display_solutions({a: [sol] for a, sol in zip(BASE_VALUES, base_solutions['single']) if sol}, 1)
  330.  
  331. # 显示双变量解
  332. if base_solutions['two'] and len(base_solutions['two']) > 0:
  333. has_solution = True
  334. display_solutions(base_solutions['two'], 2)
  335.  
  336. # 单变量和双变量都无解时,尝试三变量解
  337. if not has_solution:
  338. print(f"\n==== 单变量和双变量无解,尝试三变量解 ====")
  339. base_solutions['three'] = run_with_timeout(find_three_variable_solutions, args=(BASE_VALUES,))
  340.  
  341. if base_solutions['three'] and len(base_solutions['three']) > 0:
  342. has_solution = True
  343. display_solutions(base_solutions['three'], 3)
  344.  
  345. # 如果找到解,退出程序
  346. if has_solution:
  347. print(f"\n使用基础系数列表,共找到有效解")
  348. return
  349.  
  350. # 如果基础系数没有找到解,尝试波动系数
  351. print(f"\n==== 尝试波动系数 ====")
  352.  
  353. # 检查目标值是否超过阈值
  354. if TARGET > THREE_VAR_THRESHOLD:
  355. print(f"目标值 {TARGET} 超过阈值 {THREE_VAR_THRESHOLD},只尝试三变量解")
  356. fluctuated_solutions = {
  357. 'single': [],
  358. 'two': [],
  359. 'three': run_with_timeout(find_three_variable_solutions, args=(FLUCTUATED_VALUES,))
  360. }
  361.  
  362. # 显示三变量解
  363. if fluctuated_solutions['three'] and len(fluctuated_solutions['three']) > 0:
  364. display_solutions(fluctuated_solutions['three'], 3)
  365. print(f"\n使用波动系数列表,共找到有效解")
  366. return
  367. else:
  368. # 目标值未超过阈值,按顺序尝试单、双、三变量解
  369. fluctuated_solutions = {
  370. 'single': run_with_timeout(find_single_variable_solutions, args=(FLUCTUATED_VALUES,)),
  371. 'two': run_with_timeout(find_two_variable_solutions, args=(FLUCTUATED_VALUES,)),
  372. 'three': []
  373. }
  374.  
  375. # 重置标志
  376. has_solution = False
  377.  
  378. # 显示单变量解
  379. if fluctuated_solutions['single']:
  380. has_solution = True
  381. display_solutions({a: [sol] for a, sol in zip(FLUCTUATED_VALUES, fluctuated_solutions['single']) if sol}, 1)
  382.  
  383. # 显示双变量解
  384. if fluctuated_solutions['two'] and len(fluctuated_solutions['two']) > 0:
  385. has_solution = True
  386. display_solutions(fluctuated_solutions['two'], 2)
  387.  
  388. # 单变量和双变量都无解时,尝试三变量解
  389. if not has_solution:
  390. print(f"\n==== 单变量和双变量无解,尝试三变量解 ====")
  391. fluctuated_solutions['three'] = run_with_timeout(find_three_variable_solutions, args=(FLUCTUATED_VALUES,))
  392.  
  393. if fluctuated_solutions['three'] and len(fluctuated_solutions['three']) > 0:
  394. has_solution = True
  395. display_solutions(fluctuated_solutions['three'], 3)
  396.  
  397. # 如果找到解,退出程序
  398. if has_solution:
  399. print(f"\n使用波动系数列表,共找到有效解")
  400. return
  401.  
  402. # 如果所有系数集都没有找到解
  403. print("\n没有找到符合条件的解,即使使用波动后的系数列表。")
  404.  
  405. if __name__ == "__main__":
  406. start_time = time.time()
  407. main()
  408. print(f"\n总耗时: {time.time() - start_time:.2f}秒")
Success #stdin #stdout 0.03s 11924KB
stdin
Standard input is empty
stdout
目标值: 20000

==== 尝试基础系数 ====

找到 30 组2变量解:

1. 组合: a=36.5, b=41.5 (6 个有效解)
  1. x=233, y=277.0, a*x=8504.5, b*y=11495.5, 总和=20000.0 [平衡解]
  2. x=316, y=204.0, a*x=11534.0, b*y=8466.0, 总和=20000.0 [平衡解]
  3. x=67, y=423.0, a*x=2445.5, b*y=17554.5, 总和=20000.0 [原始解]
  4. x=150, y=350.0, a*x=5475.0, b*y=14525.0, 总和=20000.0 [原始解]
  5. x=399, y=131.0, a*x=14563.5, b*y=5436.5, 总和=20000.0 [原始解]

2. 组合: a=36.5, b=59 (5 个有效解)
  1. x=160, y=240.0, a*x=5840.0, b*y=14160.0, 总和=20000.0 [平衡解]
  2. x=278, y=167.0, a*x=10147.0, b*y=9853.0, 总和=20000.0 [平衡解]
  3. x=42, y=313.0, a*x=1533.0, b*y=18467.0, 总和=20000.0 [原始解]
  4. x=396, y=94.0, a*x=14454.0, b*y=5546.0, 总和=20000.0 [原始解]
  5. x=514, y=21.0, a*x=18761.0, b*y=1239.0, 总和=20000.0 [原始解]

3. 组合: a=36.5, b=68.5 (4 个有效解)
  1. x=197, y=187.0, a*x=7190.5, b*y=12809.5, 总和=20000.0 [平衡解]
  2. x=60, y=260.0, a*x=2190.0, b*y=17810.0, 总和=20000.0 [平衡解]
  3. x=334, y=114.0, a*x=12191.0, b*y=7809.0, 总和=20000.0 [原始解]
  4. x=471, y=41.0, a*x=17191.5, b*y=2808.5, 总和=20000.0 [原始解]

4. 组合: a=36.5, b=74 (3 个有效解)
  1. x=108, y=217.0, a*x=3942.0, b*y=16058.0, 总和=20000.0 [平衡解]
  2. x=256, y=144.0, a*x=9344.0, b*y=10656.0, 总和=20000.0 [平衡解]
  3. x=404, y=71.0, a*x=14746.0, b*y=5254.0, 总和=20000.0 [原始解]

5. 组合: a=36.5, b=91.5 (3 个有效解)
  1. x=202, y=138.0, a*x=7373.0, b*y=12627.0, 总和=20000.0 [平衡解]
  2. x=19, y=211.0, a*x=693.5, b*y=19306.5, 总和=20000.0 [平衡解]
  3. x=385, y=65.0, a*x=14052.5, b*y=5947.5, 总和=20000.0 [原始解]

6. 组合: a=41.5, b=36.5 (6 个有效解)
  1. x=277, y=233.0, a*x=11495.5, b*y=8504.5, 总和=20000.0 [平衡解]
  2. x=204, y=316.0, a*x=8466.0, b*y=11534.0, 总和=20000.0 [平衡解]
  3. x=58, y=482.0, a*x=2407.0, b*y=17593.0, 总和=20000.0 [原始解]
  4. x=131, y=399.0, a*x=5436.5, b*y=14563.5, 总和=20000.0 [原始解]
  5. x=350, y=150.0, a*x=14525.0, b*y=5475.0, 总和=20000.0 [原始解]

7. 组合: a=41.5, b=59 (4 个有效解)
  1. x=172, y=218.0, a*x=7138.0, b*y=12862.0, 总和=20000.0 [平衡解]
  2. x=290, y=135.0, a*x=12035.0, b*y=7965.0, 总和=20000.0 [平衡解]
  3. x=54, y=301.0, a*x=2241.0, b*y=17759.0, 总和=20000.0 [原始解]
  4. x=408, y=52.0, a*x=16932.0, b*y=3068.0, 总和=20000.0 [原始解]

8. 组合: a=41.5, b=68.5 (3 个有效解)
  1. x=132, y=212.0, a*x=5478.0, b*y=14522.0, 总和=20000.0 [平衡解]
  2. x=269, y=129.0, a*x=11163.5, b*y=8836.5, 总和=20000.0 [平衡解]
  3. x=406, y=46.0, a*x=16849.0, b*y=3151.0, 总和=20000.0 [原始解]

9. 组合: a=41.5, b=74 (3 个有效解)
  1. x=136, y=194.0, a*x=5644.0, b*y=14356.0, 总和=20000.0 [平衡解]
  2. x=284, y=111.0, a*x=11786.0, b*y=8214.0, 总和=20000.0 [平衡解]
  3. x=432, y=28.0, a*x=17928.0, b*y=2072.0, 总和=20000.0 [原始解]

10. 组合: a=41.5, b=91.5 (2 个有效解)
  1. x=149, y=151.0, a*x=6183.5, b*y=13816.5, 总和=20000.0 [平衡解]
  2. x=332, y=68.0, a*x=13778.0, b*y=6222.0, 总和=20000.0 [平衡解]

11. 组合: a=59, b=36.5 (5 个有效解)
  1. x=240, y=160.0, a*x=14160.0, b*y=5840.0, 总和=20000.0 [平衡解]
  2. x=167, y=278.0, a*x=9853.0, b*y=10147.0, 总和=20000.0 [平衡解]
  3. x=21, y=514.0, a*x=1239.0, b*y=18761.0, 总和=20000.0 [原始解]
  4. x=94, y=396.0, a*x=5546.0, b*y=14454.0, 总和=20000.0 [原始解]
  5. x=313, y=42.0, a*x=18467.0, b*y=1533.0, 总和=20000.0 [原始解]

12. 组合: a=59, b=41.5 (4 个有效解)
  1. x=218, y=172.0, a*x=12862.0, b*y=7138.0, 总和=20000.0 [平衡解]
  2. x=135, y=290.0, a*x=7965.0, b*y=12035.0, 总和=20000.0 [平衡解]
  3. x=52, y=408.0, a*x=3068.0, b*y=16932.0, 总和=20000.0 [原始解]
  4. x=301, y=54.0, a*x=17759.0, b*y=2241.0, 总和=20000.0 [原始解]

13. 组合: a=59, b=68.5 (2 个有效解)
  1. x=130, y=180.0, a*x=7670.0, b*y=12330.0, 总和=20000.0 [平衡解]
  2. x=267, y=62.0, a*x=15753.0, b*y=4247.0, 总和=20000.0 [平衡解]

14. 组合: a=59, b=74 (4 个有效解)
  1. x=122, y=173, a*x=7198.0, b*y=12802.0, 总和=20000.0 [平衡解]
  2. x=196, y=114, a*x=11564.0, b*y=8436.0, 总和=20000.0 [平衡解]
  3. x=48, y=232, a*x=2832.0, b*y=17168.0, 总和=20000.0 [原始解]
  4. x=270, y=55, a*x=15930.0, b*y=4070.0, 总和=20000.0 [原始解]

15. 组合: a=59, b=91.5 (2 个有效解)
  1. x=187, y=98.0, a*x=11033.0, b*y=8967.0, 总和=20000.0 [平衡解]
  2. x=4, y=216.0, a*x=236.0, b*y=19764.0, 总和=20000.0 [平衡解]

16. 组合: a=68.5, b=36.5 (4 个有效解)
  1. x=187, y=197.0, a*x=12809.5, b*y=7190.5, 总和=20000.0 [平衡解]
  2. x=260, y=60.0, a*x=17810.0, b*y=2190.0, 总和=20000.0 [平衡解]
  3. x=41, y=471.0, a*x=2808.5, b*y=17191.5, 总和=20000.0 [原始解]
  4. x=114, y=334.0, a*x=7809.0, b*y=12191.0, 总和=20000.0 [原始解]

17. 组合: a=68.5, b=41.5 (3 个有效解)
  1. x=212, y=132.0, a*x=14522.0, b*y=5478.0, 总和=20000.0 [平衡解]
  2. x=129, y=269.0, a*x=8836.5, b*y=11163.5, 总和=20000.0 [平衡解]
  3. x=46, y=406.0, a*x=3151.0, b*y=16849.0, 总和=20000.0 [原始解]

18. 组合: a=68.5, b=59 (2 个有效解)
  1. x=180, y=130.0, a*x=12330.0, b*y=7670.0, 总和=20000.0 [平衡解]
  2. x=62, y=267.0, a*x=4247.0, b*y=15753.0, 总和=20000.0 [平衡解]

19. 组合: a=68.5, b=74 (2 个有效解)
  1. x=104, y=174.0, a*x=7124.0, b*y=12876.0, 总和=20000.0 [平衡解]
  2. x=252, y=37.0, a*x=17262.0, b*y=2738.0, 总和=20000.0 [平衡解]

20. 组合: a=68.5, b=91.5 (1 个有效解)
  1. x=125, y=125.0, a*x=8562.5, b*y=11437.5, 总和=20000.0 [平衡解]

21. 组合: a=74, b=36.5 (3 个有效解)
  1. x=217, y=108.0, a*x=16058.0, b*y=3942.0, 总和=20000.0 [平衡解]
  2. x=144, y=256.0, a*x=10656.0, b*y=9344.0, 总和=20000.0 [平衡解]
  3. x=71, y=404.0, a*x=5254.0, b*y=14746.0, 总和=20000.0 [原始解]

22. 组合: a=74, b=41.5 (3 个有效解)
  1. x=194, y=136.0, a*x=14356.0, b*y=5644.0, 总和=20000.0 [平衡解]
  2. x=111, y=284.0, a*x=8214.0, b*y=11786.0, 总和=20000.0 [平衡解]
  3. x=28, y=432.0, a*x=2072.0, b*y=17928.0, 总和=20000.0 [原始解]

23. 组合: a=74, b=59 (4 个有效解)
  1. x=173, y=122, a*x=12802.0, b*y=7198.0, 总和=20000.0 [平衡解]
  2. x=114, y=196, a*x=8436.0, b*y=11564.0, 总和=20000.0 [平衡解]
  3. x=55, y=270, a*x=4070.0, b*y=15930.0, 总和=20000.0 [原始解]
  4. x=232, y=48, a*x=17168.0, b*y=2832.0, 总和=20000.0 [原始解]

24. 组合: a=74, b=68.5 (2 个有效解)
  1. x=174, y=104.0, a*x=12876.0, b*y=7124.0, 总和=20000.0 [平衡解]
  2. x=37, y=252.0, a*x=2738.0, b*y=17262.0, 总和=20000.0 [平衡解]

25. 组合: a=74, b=91.5 (1 个有效解)
  1. x=112, y=128.0, a*x=8288.0, b*y=11712.0, 总和=20000.0 [平衡解]

26. 组合: a=91.5, b=36.5 (3 个有效解)
  1. x=138, y=202.0, a*x=12627.0, b*y=7373.0, 总和=20000.0 [平衡解]
  2. x=211, y=19.0, a*x=19306.5, b*y=693.5, 总和=20000.0 [平衡解]
  3. x=65, y=385.0, a*x=5947.5, b*y=14052.5, 总和=20000.0 [原始解]

27. 组合: a=91.5, b=41.5 (2 个有效解)
  1. x=151, y=149.0, a*x=13816.5, b*y=6183.5, 总和=20000.0 [平衡解]
  2. x=68, y=332.0, a*x=6222.0, b*y=13778.0, 总和=20000.0 [平衡解]

28. 组合: a=91.5, b=59 (2 个有效解)
  1. x=98, y=187.0, a*x=8967.0, b*y=11033.0, 总和=20000.0 [平衡解]
  2. x=216, y=4.0, a*x=19764.0, b*y=236.0, 总和=20000.0 [平衡解]

29. 组合: a=91.5, b=68.5 (1 个有效解)
  1. x=125, y=125.0, a*x=11437.5, b*y=8562.5, 总和=20000.0 [平衡解]

30. 组合: a=91.5, b=74 (1 个有效解)
  1. x=128, y=112.0, a*x=11712.0, b*y=8288.0, 总和=20000.0 [平衡解]

使用基础系数列表,共找到有效解

总耗时: 0.00秒