fork download
  1. # ====================== 配置区 ======================
  2. total = 153.8 # 可改:144.6 / 241.64 / 任意总数
  3. price = 64.5 # 可改:64.5 / 65 / 任意单价
  4. # ====================================================
  5.  
  6. import random
  7. random.seed(1)
  8.  
  9. # 核心:单个金额不能超过1000元
  10. max_single = round(1000 / price, 2)
  11. count = int(total / max_single) + 1
  12. nums = []
  13. used = set()
  14. base = round(total / count, 2)
  15.  
  16. # 生成:均匀 + 不超1000 + 合规 + 不重复
  17. for i in range(count):
  18. val = round(base + i * 0.02, 2)
  19.  
  20. # 强制不超过最大值(永远不超1000)
  21. if val > max_single:
  22. val = max_single
  23.  
  24. # 保证乘积是两位小数
  25. for _ in range(500):
  26. if (val * price * 100).is_integer():
  27. break
  28. val = round(val - 0.01, 2)
  29.  
  30. # 保证不重复
  31. while val in used:
  32. val = round(val - 0.02, 2)
  33. used.add(val)
  34. nums.append(val)
  35.  
  36. # 校准总和
  37. current_sum = sum(nums)
  38. diff = round(total - current_sum, 2)
  39. if abs(diff) > 0.01:
  40. for i in range(len(nums)):
  41. new_val = round(nums[i] + diff, 2)
  42. if 0 < new_val <= max_single and new_val not in used:
  43. nums[i] = new_val
  44. break
  45.  
  46. # 输出(你要的干净格式)
  47. for num in nums:
  48. print(f"{num:.2f}")
  49.  
  50. print(f"\n总和校验:{sum(nums):.2f}")
Success #stdin #stdout 0.02s 11580KB
stdin
Standard input is empty
stdout
15.04
15.40
15.42
15.44
15.46
15.48
15.50
15.38
15.36
15.32

总和校验:153.80