很多小伙伴为了刷题发愁
今天为大家推荐一款刷题神奇哦:刷题面试神器牛客
各大互联网大厂面试真题。从基础到入阶乃至原理刨析类面试题 应有尽有,赶快来装备自己吧!助你面试稳操胜券,solo全场面试官.

#include
using namespace std;
int main() {
int n;
while (cin >> n) {
int count = 0;
if(n == 0)
break;
while (n != 0) {
if (n == 2)
{
count += 1;
n = 0;
}
else if(n == 1)
break;
else
{
count += n / 3;
n = n / 3 + n % 3;
}
}
cout<< count< 即按照题目的常规思路写下去
某商店规定:三个空汽水瓶可以换一瓶汽水,允许向老板借空汽水瓶(但是必须要归还)。
题目链接:链接
代码实现:
class Solution {
public:
int jumpFloorII(int number) {
return pow(2,number-1);
}
};
class Solution {
public:
int jumpFloorII(int number) {
return 1<<(number-1);
}
};
以后遇到2的次方运算时,应用位运算来提高效率

// write your code here cpp
#include
#include
using namespace std;
int main() {
int board = -1;
long long ans[100000];
ans[0] = 1;
ans[1] = 2;
for (int i = 2; i < 100000; i++) {
long long next = ans[i - 1] + ans[i - 2];
if( board == -1 && next >= 1000000 ) //首次出现
{
board = i+1;
}
ans[i] = next % 1000000;
}
int n;
while (cin >> n) {
long long f = ans[n - 1];
if(n>=board)
printf("%06d\n",f);
else
printf("%d\n", f);
}
}