NC25002. [USACO 2008 Ope S]Roads Around The Farm
描述
输入描述
* Line 1: Two space-separated integers: N and K
输出描述
* Line 1: A single integer representing the number of groups of grazing cows
示例1
输入:
6 2
输出:
3
说明:
There are 3 final groups (with 2, 1, and 3 cows in them).C++ 解法, 执行用时: 4ms, 内存消耗: 408K, 提交时间: 2022-01-17 13:02:40
#include <bits/stdc++.h> using namespace std; int n,k; int f(int n) { if((n+k)%2||n<=k) return 1; int x; return f(x=(n+k)/2)+f(n-x); } int main() { cin>>n>>k; cout<<f(n); return 0; }