CodeLibrary/03_Clion_Cplus_assignment_20240421/main.cpp

116 lines
3.1 KiB
C++
Raw Permalink Normal View History

/*
* Code:
* Date: 2024-04-21
* Design by JRNitre
*
* Function:
* *
* *
* */
#include <iostream>
using namespace std;
/*
* []
* 2/32/32/3n天早上想再吃时k个桃子了
* Input
* TT组测试数据nk1nk15
* Output
*
*/
int function_01 (int t, int n, int k){
int i,j;
for (i = 0; i < t; i++){
int peaches[n+1];
peaches[n] = k;
for (j = n; j > 1; j--){
peaches[j-1] = (peaches[j] + 1) * 3 / 2;
}
return peaches[1];
}
}
// 分别从键盘输入数据x和y计算x的y次幂并输出。
int function_02 (int x, int y){
if (y == 1){
return x;
}
if (y >= 2){
int result = 1;
for (int i = 0; i < y; i++){
result *= x;
}
return result;
}
}
/*
* []
* 4n年时有多少头母牛
* Input
* n1n40
* Output
* n年时的母牛总数
* Sample Input
* 15
* Sample Output
* 129
*/
int function_03_recursion(int n) {
int dp[n+1];
dp[1] = 1;
dp[2] = 2;
dp[3] = 3;
for (int i = 4; i <= n; i++) {
dp[i] = dp[i-1] + dp[i-3];
}
return dp[n] / 2;
}
int function_03_recursion2(int n){
if (n == 1 || n == 2 || n == 3) {
return n;
}
return function_03_recursion2(n-1) + function_03_recursion2(n-3);
}
/*
* []
*
* ?
*
*/
int function_04(int n) {
if (n == 1) {
return 0;
} else if (n == 2) {
return 1;
} else {
return (n - 1) * (function_04(n - 1) + function_04(n - 2));
}
}
/*
* []
*
*
* n
* */
int function_05 (int n){
if (n == 1){
return 0;
}
if (n == 2){
return 1;
}
if (n > 2){
return (n - 1) * (function_05(n - 1) + function_05(n - 2));
}
}
int main() {
return 0;
}