| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 130167 | 胡海峰老师 | 06买鸡腿 | C++ | Accepted | 2 MS | 272 KB | 706 | 2025-09-07 19:25:20 |
#include <iostream> using namespace std; // 递归函数:计算能吃多少鸡腿 int eatChicken(int money, int price, int count) { if (money < price) { return 0; } // 买一个鸡腿 int bought = 1; int remaining_money = money - price; // 如果这是第3个鸡腿,送一个 if (count == 2) { // 注意:count从0开始,2表示第3个 bought += 1; // 送一个 return bought + eatChicken(remaining_money, price, 0); } return bought + eatChicken(remaining_money, price, count + 1); } int main() { int a, b; cin >> a >> b; cout << eatChicken(b, a, 0) << endl; return 0; }