hihocoder 1288 : Font Size (微软2016校园招聘4月在线笔试)

hihocoder 1288

笔试第一道。。wa了好几次,也是无语。。hihocoder错了不会告诉你失败的时候的测试集,这样有时候就很烦。。

遍历所有的字体,从min(w,h)开始逐渐变小开始遍历。。计算行数,和all行数比较,只要比他小就可以。。

我太瓜皮了。

#include <iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
    int testn,n,p,w,h;
    cin>>testn;
    while(testn--)
    {
        cin>>n>>p>>w>>h;
        int a[n];
        for(int i=0; i<n; i++)
            cin>>a[i];
        int up=min(w,h);
        bool flag=false;

        for(int i=up; i>=1; i--)
        {
            int temph=0;
            int allh=(h/i)*p;
            for(int j=0; j<n; j++)
            {
                temph+=a[j]/(w/i);
//这里表示开始分段了
if(a[j]%(w/i)) temph++; } if(temph<=allh) {cout<<i<<endl; flag=true; break;} } if(!flag) cout<<0<<endl; } return 0; }
原文地址:https://www.cnblogs.com/weedboy/p/6820966.html