#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int people(int* a, int i, int k)
{
int sum = 0, flag = 0, b = 0;
while (b < i)
{
if (sum < k) //判断是否超重
{
sum = *a + sum;
a++;
}
else
{
sum = 0;
flag++;
b--; //如果进入else,则此次循环a没有变,b也不变
}
b++;
}
if (sum < k && sum != 0) { flag++; }
return flag;
}
int main()
{
int n, k, arr[1001], b = 0;
scanf("%d %d", &n, &k);
while (b < n)
{
scanf("%d", &arr[b]);
b++;
}
printf("%d", people(arr, n, k));
return 0;
}
XDOJ 竞赛训练题2 分蛋糕
最新推荐文章于 2024-11-14 15:56:18 发布