Problem Description
The yearly sports meeting is approaching in Hail university and M departments, conveniently numbered from 1 to M, are going to take part in. Each department has no more than h students.
Now send ai students from the i-th department as spectators, such that ∑i=1Mai=L. There are k seats every row on the grandstand and Lmodk=0. Students from the same department are required to sit in the same row. The question is how many rows should be arranged at least, to ensure that no matter of the values of M and a1,⋯,am, all the students will be able to get seated.
Input
Multiple test cases, process till end of input.
For each case, the one and only line contains three space-separated integers h,L,k as stated above.
You can assume that
0<h≤1000
0<L≤1000000000,
0<k≤1000000, and
Lmodk=0.
Output
Output a positive integer X on a single line showing the least rows needed.
Sample Input
39 2020 202
Sample Output
12
题意:有好多班级要去参加一个会议,给出h表示每个班级的最多人数,L表示会场的人数,k表示每排的座位数,问最少的排数。
一下解析都是猜测,居然过了。。。
目的就是要让每个班级人数尽量一样,而每排空出的人数尽量多。首先每个班级若按照最大人数每排能坐多少个班级,然后每排多坐一个班级每班级多少人,这样每班的人数就是这个人数 +1。然后算出有多少排,如果不能正好完全坐好,就多坐一排。
#include <cstdio>
int main()
{
int h, L, K;
while (scanf("%d%d%d", &h, &L, &K) != EOF)
{
int num = K/h;
h = K/(num + 1);
int H = h + 1;
int rows = L/(K - K%H);
if (L % (K - K%H) > 0)
rows++;
printf("%d\n", rows);
}
return 0;
}