Seats
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 262 Accepted Submission(s): 83
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
Source
2016 ACM/ICPC Asia Regional Dalian Online
贪心
考虑
ai=num //i<=n-1
an=L%num
显然 每排最多只能放k/h个部门
当k/num=k/h 且num最小时
需要的排数最多
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<math.h>
#include<list>
#include<cstring>
#include<fstream>
//#include<memory.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define INF 1000000007
#define pll pair<ll,ll>
#define pid pair<int,double>
int main()
{
//freopen("/home/lu/文档/r.txt","r",stdin);
//freopen("/home/lu/文档/w.txt","w",stdout);
int h,L,k;
while(~scanf("%d%d%d",&h,&L,&k)){
int t=k/h;//每排最多t个部门
int num=k/(t+1)+1;//一排最多放t个部门 则每个部门最少有num人
t=k/num;
t=t*num;//每排有t人
int ans=L/t+(L%t>0);//能放多少排
printf("%d\n",ans);
}
return 0;
}