2021-08-18
Posted 李憨憨_
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2021-08-18相关的知识,希望对你有一定的参考价值。
练习一
HJ91走方格的方案数
题目描述:
#include <iostream>
using namespace std;
int pathWay(int n, int m)
if(n == 0 || m == 0)
return 1;
return pathWay(n - 1, m) + pathWay(n, m - 1);
int main()
int n, m;
while(cin >> n >> m)
cout << pathWay(n, m) << endl;
return 0;
练习二
class LCA
public:
int getLCA(int a, int b)
// write code here
while(a != b)
if(a > b)
a = a / 2;
else
b = b / 2;
return a;
;
练习三
#include <iostream>
using namespace std;
int main()
int num;
while(cin >> num)
int count = 0, max_count = 0;
while(num)
if(num & 1)
count++;
max_count = max(count, max_count);
else
count = 0;
num = num >> 1;
cout << max_count << endl;
return 0;
正确代码:
#include <iostream>
using namespace std;
int main()
int num;
while(cin >> num)
int count = 0, max_count = 0;
for(int i = 0; i < 32; ++i)
if(num & (1 << i))
count++;
max_count = max(count, max_count);
else
count = 0;
cout << max_count << endl;
return 0;
以上是关于2021-08-18的主要内容,如果未能解决你的问题,请参考以下文章