热心的牛牛
class Solution {
public:
/**
* 返回牛牛能吃到的最多糖果数
* @param n long长整型
* @param k long长整型
* @return long长整型
*/
long long Maximumcandies(long long n, long long k) {
// write code here
return (k-n)/(n+1);
}
};
牛牛切木棒
class Solution {
public:
/**
*
* @param a long长整型 木棒的长度
* @return int整型
*/
int stick(long long a) {
ull ans = 2;
ull now = 1, sum = 2;
ull x = 1, y = 1;
if(a == 1) {puts("1"); return 0;}
while(1)
{
now = x + y;
if(now > a - sum ) break;
now = x + y;
x = y;
y = now;
ans ++;
sum = sum + now;
}
return ans;
// write code here
}
};
Tree II
class Solution
{
public:
typedef long long ll;
ll n, k, d[100010];
ll ans = 0;
inline void dfs(ll x)
{
for (ll i = -k + 2; i <= 1; ++i)
{
if (x * k + i <= n)
{
dfs(x * k + i);
ans += (d[x] ^ d[x * k + i]);
}
else
return;
}
}
long long tree2(int K, vector<int> &a)
{
n = a.size();
k = K;
for (int i = 0; i < n; ++i)
{
d[i + 1] = a[i];
}
dfs(1);
return ans;
}
};
全部评论
(1) 回帖