题解 | #统计每个月兔子的总数#
统计每个月兔子的总数
https://www.nowcoder.com/practice/1221ec77125d4370833fd3ad5ba72395
#include <stdio.h> #include <math.h> int main() { int n = 0; unsigned int m1Num = 1; unsigned int m2Num = 0; unsigned int m3Num = 0; unsigned int mnNum = 0; unsigned int m1Num_ = 1; unsigned int m2Num_ = 0; unsigned int m3Num_ = 0; unsigned int mnNum_ = 0; scanf("%d",&n); for(int i = 0; i < n; i++) { if(0 == i){ m2Num_ = 0; m3Num_ = 0; m1Num_ = 1; mnNum_ = 0; }else if(1 == i){ m2Num_ = 1; m3Num_ = 0; m1Num_ = 0; mnNum_ = 0; } else{ m2Num_ = m1Num; m3Num_ = m2Num; mnNum_ += m3Num; m1Num_ = m2Num + m3Num + mnNum; } m1Num = m1Num_; m2Num = m2Num_; m3Num = m3Num_; mnNum = mnNum_; } printf("%ld",(m1Num+m2Num+m3Num+mnNum)); return 0; }