题解 | 鸡兔同笼
鸡兔同笼
https://www.nowcoder.com/practice/fda725b4d9a14010bb145272cababef1
#include <iostream>
using namespace std;
int main() {
int a;
while (cin >> a) {
if (a & 1) {
cout << "0 0" << endl;
} else {
cout << (a + 2) / 4 << " " << a / 2 << endl;
}
}
return 0;
}
对于奇数条腿,已经没有人类了;
对于偶数条腿,如果全为兔子,则数量最少,所以除4,但考虑到多出一只鸡的特殊情况,所以是 (a + 2)/4
查看17道真题和解析