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--是因为出循环的时候多加了一次

全部评论

相关推荐

02-03 12:20
门头沟学院 Java
一天代码十万三:你这个简历东西太杂了,根本看不出你想投什么岗位
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务