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-20 19:40
中原工学院 Java
网络存储:十几天不会让你拉人办卡就结束了吧?
点赞 评论 收藏
分享
程序员饺子:正常 我沟通了200多个 15个要简历 面试2个 全投的成都的小厂。很多看我是27直接不会了😅
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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