Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
148139 冯祥瑞 小明养猪的故事 C++ Wrong Answer 0 MS 268 KB 594 2026-02-09 17:28:06

Tests(0/1):


Code:

#include <iostream> using namespace std; // 计算第n天猪的总数 long long countPigs(int n) { if (n <= 2) return n; // 前2天直接返回天数 long long prev = 1, curr = 2, total = 2; // 初始化第1、2天的猪数及总数 for (int i = 3; i <= n; ++i) { long long next = total + 1; // 当天总数=前一天总数+1(当天新买) prev = curr; curr = next; total = next; // 更新状态 } return total; } int main() { int n; cin >> n; // 输入天数 cout << countPigs(n) << endl; // 输出结果 return 0; }


Run Info:

------Input------
17 1 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
------Answer-----
1 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
------Your output-----
17