第一题完成 是比较简单的!代码如下:
#include<iostream>
#include<stdio.h>
using namespace std;
int n,w,h,p;
int a[1010];
bool check (int s)
{
if (w<s || h<s) return 0;
int nowx,nowy;
int x=w/s;
int y=h/s;
int tot=0;
int pages=0;
for (int i=1;i<=n;i++)
{
tot+=a[i]/x;
if (a[i]%x) tot++;
while (tot>y)
{
tot-=y;
pages++;
}
if (pages>p) return 0;
}
if (tot) pages++;
if (pages<=p) return 1;
return 0;
}
void doing ()
{
cin>>n>>p>>w>>h;
for (int i=1;i<=n;i++)
cin>>a[i];
int left,right,ans;
left=0;right=200000000;
while (left<=right)
{
int mid=(left+right)>>1;
if (check(mid)){
ans=mid;
left=mid+1;
}
else right=mid-1;
}
cout<<ans<<endl;
}
int main ()
{
int T;
cin>>T;
while (T--)
doing ();
return 0;
}