| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 160672 | 李茂铭 | 百钱买百鸡II | Python3 | Compile Error | 0 MS | 0 KB | 1765 | 2026-09-26 09:56:55 |
def solve_chicken_problem(N): solutions = [] # x 是公鸡数量,范围从 0 到 N // 7 # 因为 7x <= N => x <= N/7 max_x = N // 7 for x in range(0, max_x + 1): remainder = N - 7 * x # y 必须是整数,所以 remainder 必须能被 4 整除 if remainder % 4 == 0: y = remainder // 4 # 计算小鸡数量 z = N - x - y # 确保 z 是非负数 if z < 0: continue # 题目隐含条件:小鸡3只1钱,通常要求 z 是 3 的倍数 # 虽然数学上 7x+4y=N 是由价格方程推导来的,但我们需要确保 z/3 是合法的 # 在实际整数运算中,如果 z % 3 != 0,则 5x + 3y + z/3 不会等于整数 N (除非题目允许小数钱,但通常这类题指整数钱) # 验证:如果 z % 3 == 0,则方案有效 if z % 3 == 0: solutions.append((x, y, z)) return solutions def main(): try: # 读取输入 import sys input_data = sys.stdin.read().split() if not input_data: return N = int(input_data[0]) # 获取所有解 sols = solve_chicken_problem(N) if not sols: print("None") else: for i, (x, y, z) in enumerate(sols): # 输出格式:第几种方案: 公鸡数,母鸡数,小鸡数 # 方案编号从1开始 print(f"{i+1}: {x},{y},{z}") except Exception as e: pass if __name__ == "__main__": main()
File "Main.py", line 48
print(f"{i+1}: {x},{y},{z}")
^
SyntaxError: invalid syntax