llllmz

导航

2024年1月22日

KY85 二叉树C++

摘要: 递归判断当前节点和n的关系就好了。如果小于等于n那就是存在。 #include<iostream> using namespace std; int count(int i,int n){ if(i>n) return 0; return count(2*i,n)+ count(2*i+1,n)+1 阅读全文

posted @ 2024-01-22 20:16 神奇的萝卜丝 阅读(24) 评论(0) 推荐(0)

KY96 FibonacciC++

摘要: #include<iostream> using namespace std; int compute(int n){ if(n==1) return 1; if(n==0) return 0; return compute(n-1)+ compute(n-2); } int main(){ int 阅读全文

posted @ 2024-01-22 19:59 神奇的萝卜丝 阅读(15) 评论(0) 推荐(0)

4147:汉诺塔问题(Tower of Hanoi)C++

摘要: 递归C和C++一样,就写个C++了。 #include<iostream> using namespace std; void move(int n,char a,char b,char c){ if(n<=0) return; move(n-1,a,c,b); cout << n << ":"<< 阅读全文

posted @ 2024-01-22 17:05 神奇的萝卜丝 阅读(32) 评论(0) 推荐(0)

KY17 n的阶乘C++

摘要: 递归一下。 #include<iostream> using namespace std; long compute(int n){ if(n==1) return 1; return n* compute(n-1); } int main(){ int n; while( cin >> n){ c 阅读全文

posted @ 2024-01-22 15:58 神奇的萝卜丝 阅读(14) 评论(0) 推荐(0)