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

全部评论

相关推荐

完美的潜伏者许愿简历...:隐藏信息被你提取出来了,暗示,这就是暗示
点赞 评论 收藏
分享
06-11 17:39
门头沟学院 Java
小呆呆的大鼻涕:卧槽,用户彻底怒了
点赞 评论 收藏
分享
06-23 11:43
门头沟学院 Java
allin校招的烤冷...:我靠,今天中午我也是这个hr隔一个星期发消息给我。问的问题还是一模一样的😅
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务