题意:给定一个宽度为和高度为的屏幕,如果字体的大小为,那么一行可以显示个字,每一页可以显示行。给出段文本段落,每段有个文字,问现在能设置的最大字体并且总的页数不能超过?


思路:如果知道字体大小很容易求得需要的页面数。暴力枚举字体的大小的时间复杂度是。可以用二分做到

AC代码

 #include <cstdio>
#include <cmath>
#include <cctype>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
const int maxn = 1000 + 5;
int a[maxn];
int n, p, w, h;
//ceil() 向上取整

bool check(int fsize) {
    if(fsize > h) return false;
    int len = w / fsize;
    int col = 0;
    for(int i = 0; i < n; ++i) {
        col += ceil(1.0*a[i]/len);
    }
    int par = ceil(col*1.0/(h/fsize));
    return par <= p;
}

int solve(int x, int y) {
    while(x < y) {
        int mid = (x+y) / 2;
        if(check(mid)) x = mid+1;
        else y = mid;
    }
    return x-1;
}
int main() {
    int T;
    scanf("%d", &T);
    while(T--) {
        scanf("%d%d%d%d", &n, &p, &w, &h);
        for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
        printf("%d\n", solve(1, w+1));
    }
    return 0;
}

如有不当之处欢迎指出!

hihoCoder 1288 Font Size 二分的更多相关文章

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

    hihocoder 1288 笔试第一道..wa了好几次,也是无语..hihocoder错了不会告诉你失败的时候的测试集,这样有时候就很烦.. 遍历所有的字体,从min(w,h)开始逐渐变小开始遍历. ...

  2. ACM学习历程—Hihocoder 1288 Font Size(暴力 || 二分)

    http://hihocoder.com/problemset/problem/1288 这题是这次微软笔试的第一题,关键的是s的上限是min(w, h),这样s的范围只有到1000,这样就可以直接暴 ...

  3. 【hihoCoder】1288 : Font Size

    题目:http://hihocoder.com/problemset/problem/1288 手机屏幕大小为 W(宽) * H(长),一篇文章有N段,每段有ai个字,要求使得该文章占用的页数不超过P ...

  4. hiho #1288 微软2016.4校招笔试题 Font Size

    #1288 : Font Size 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Steven loves reading book on his phone. The ...

  5. LaTeX :font size 修改字体大小的几种方式

    调整字体大小的几种方式,大小依次增大,具体如下: \tiny \scriptsize \footnotesize \small \normalsize \large \Large \LARGE \hu ...

  6. GetPropInfo Font Size

    设置font size,遍历所有控件,有的控件没有font属性,所以要用GetPropInfo判断 if (GetPropInfo(cmp, "font")) function G ...

  7. unity UGUI text font size对性能影响较大

    Font Size对ugui text的性能影响非常大. <Cube Duck Run>在itouch5上测试是很流畅的,但是在iphone5上测试,在game over后显示历史最高分时 ...

  8. XE6 c++builder 设置 font size GetPropInfo SetOrdProp

    PPropInfo ppi; PTypeInfo pti; TTypeKinds ttk; TRttiContext context; TRttiType *rttiType TObject* obj ...

  9. UIAlertController custom font, size, color

    本文转载至 http://stackoverflow.com/questions/26460706/uialertcontroller-custom-font-size-color up vote2d ...

随机推荐

  1. CSS深入理解学习笔记之z-index

    1.z-index基础 z-index含义:指定了元素及其子元素的"z顺序",而"z顺序"可以决定元素的覆盖顺序.z-index值越大越在上面. z-index ...

  2. SQLSERVER存储过程语法详解

    CREATE PROC [ EDURE ] procedure_name [ ; number ] [ { @parameter data_type } [ VARYING ] [ = default ...

  3. linkin大话面向对象--抽象类

    abstract [非private访问修饰符] 返回值类型 方法名称(参数列表); 当编写一个类时,我们往往会为该类定义一些方法,这些方法时用来描述该类的行为方式,那么这些方法都有具体的方法体. 但 ...

  4. XML (一)

    1 XML概述 XML是指可扩展的标记语言,很类似与HTML.它被设计的宗旨就是描述数据,而非显示数据. XML标签没有被预定义,需要用户自定定义标签. XML技术是W3C组织发布的.目前遵循的规范是 ...

  5. js禁止滚动条移动

    js禁止滚动条移动 var scrollFunc=function(e){ e=e||window.event; if (e&&e.preventDefault){ e.prevent ...

  6. Part 3:视图和模板--Django从入门到精通系列教程

    该系列教程系个人原创,并完整发布在个人官网刘江的博客和教程 所有转载本文者,需在顶部显著位置注明原作者及www.liujiangblog.com官网地址. Python及Django学习QQ群:453 ...

  7. 【转】shell学习笔记(六)——流程控制之for循环

    基本语法格式: for 变量 in 列表 do 命令行(通常用到循环变量) done ********Linux Shell for循环写法总结******** for((i=1;i<</ ...

  8. Linux时间转标准时间

    [root@nhserver2 ~]# date -d '1970-1-1 0:0:0 GMT + 1394592071 seconds'Wed Mar 12 10:41:11 CST 2014

  9. H3c交换机配置端口镜像详情

    端口镜像 需要将G0/0/1口的全部流量镜像到G0/0/2口,即G0/0/1为源端口,G0/0/2为目的端口. 配置步骤 1.进入配置模式:system-view: 2.创建本地镜像组:mirrori ...

  10. remap.config文件配置模板

    # # URL Remapping Config File # # Using remap.config allows you to accomplish two things: # # 1) Rew ...