本题链接:201703-1 分蛋糕
本博客给出本题截图:
C++
#include <iostream> using namespace std; const int N = 1010; int n, k; int a[N]; int main() { cin >> n >> k; for (int i = 0; i < n; i ++ ) cin >> a[i]; int res = 0; for (int i = 0; i < n; i ++ ) { int j = i, s = 0; while (j < n && s < k) s += a[j ++ ]; res ++ ; i = j - 1; } cout << res << endl; return 0; }
总结
水题,不解释