CSP题解|201703-1 分蛋糕|100分
#include <bits/stdc++.h>
using namespace std;
int main() {
int cakeNum,threshold,num=0;
cin>>cakeNum>>threshold;
int cake[cakeNum];
for(int i =0;i<cakeNum;i++){
cin>>cake[i];
}
//开始分配
for(int i =0;i<cakeNum;i++){
int get=0;
while(get<threshold &&i<cakeNum){
get+=cake[i];
i++;
}
i--;
if(get>=0)num++;
}
cout<<num<<endl;
}
i--是因为出循环的时候多加了一次
海康威视公司福利 1182人发布
查看19道真题和解析