题目链接:Codeforces 435A Queue on Bus Stop
#include <iostream>
using namespace std;
const int MAX_N = 100 + 10;
int arr[MAX_N];
int main()
{
int n, m, cnt = 0, temp = 0;
cin >> n >> m;
for(int i = 0; i < n; i++)
cin >> arr[i];
for(int i = 0; i < n; i++)
{
if(arr[i] == m)
cnt++;
else
{
temp = arr[i];
i++;
for(; i < n; i++)
{
if(temp + arr[i] > m)
{
cnt++;
i--;
temp = 0;
break;
}
else
{
temp += arr[i];
}
}
}
}
if(temp)
cnt++;
cout << cnt << endl;
return 0;
}
本文详细解析了Codeforces435A题目的算法实现过程,通过遍历数组并使用计数变量来计算在公交车站排队的人群能够分成多少组的问题。该算法考虑了每组人的总重量不能超过给定限制的情况。
141

被折叠的 条评论
为什么被折叠?



