1 条题解
-
0
练39.3 鸡兔同笼
解题思路
35只都当鸡有70只脚,实际多24脚,每只兔多2脚,兔12、鸡23。
正确性说明
计算规则直接来自题目定义。按所述顺序处理时,已完成部分的结果被准确保存在累加量、计数或当前状态中;下一步只加入新增贡献。最终得到完整要求的结果。
易错点
题目输出先鸡后兔,带中文标签。
复杂度
时间O(1),空间O(1)。
参考代码(C++11)
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int rabbit = (94 - 35 * 2) / 2; cout << "鸡:" << 35 - rabbit << " 兔:" << rabbit << "\n"; return 0; }
- 1