微软一道简单笔试题

题目非常简单,主要是读控制台输入数据有些忘了,所以折腾有点久。写的好像有点复杂,最终还是实现了。。。。

public class MaxFont {

    int n;
    int p;
    int w;
    int h;
    public MaxFont(int n,int p,int w,int h){
        this.n=n;
        this.p=p;
        this.w=w;
        this.h=h;
    }

    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub

        ArrayList<String> inputList=new ArrayList<String>();

        Scanner sc=new Scanner(System.in);
        int numOfCase=Integer.parseInt(sc.nextLine());
        int[] result=new int[numOfCase];
        int i=0;
        int s=0;
        while(i<2*numOfCase-1){
            String npwn=sc.nextLine();
            String parCont=sc.nextLine();

            String[] temp=npwn.split(" ");
            int[] intTemp=new int[temp.length];
            for(int j=0;j<temp.length;j++){
                intTemp[j]=Integer.parseInt(temp[j]);
            }

            String[] temp2=parCont.split(" ");
            int[] intTemp2=new int[temp2.length];
            for(int j=0;j<temp2.length;j++){
                intTemp2[j]=Integer.parseInt(temp2[j]);
            }

            MaxFont mf=new MaxFont(intTemp[0], intTemp[1], intTemp[2], intTemp[3]);
            int t=mf.maxFont(intTemp2);
            result[s++]=t;
            i=i+2;
        }

        for (int m : result) {
            System.out.println(m);
        }

    }

    public  int maxFont(int[] arr){
        int maxFont=0;
        int pages=0;
        int remainRows=0;
        while(pages<p){
            maxFont++;
            pages=0;
            remainRows=0;
            int w1=w/maxFont;
            int h1=h/maxFont;
            for(int i=0;i<n;i++){
                pages+=arr[i]/(w1*h1);
                remainRows+=arr[i]%(w1*h1);
            }
            pages+=remainRows/h1+1;
        }

        return maxFont;
    }

}
时间: 2024-08-01 22:40:57

微软一道简单笔试题的相关文章

2015微软实习在线笔试题 - Professor Q&#39;s Software

时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new software. The software consists of N modules which are numbered from 1 to N. The i-th module will be started up by signal Si. If signal Si is generated multiple times, the i-th module

一道java笔试题

输入一串用空格隔开的数字串,对于数字串的奇数位按升序排序,偶数位按降序排序. 示例输入: 4 6 2 3 6 7 8 1 处理过程: 奇数位:4 2 6 8 升序排序结果: 2 4 6 8 偶数位:6 3 7 1 降序排序结果: 7 6 3 1 结果输出:2 7 4 6 6 3 8 1 demo: import java.util.*; public class Main { public static void main(String args[]) { Scanner scan = new 

微软2017校招笔试题3 registration day

题目 It's H University's Registration Day for new students. There are M offices in H University, numbered from 1 to M. Students need to visit some of them in a certain order to finish their registration procedures. The offices are in different places.

从网易的一道多线程笔试题学习wait与notify来控制线程同步

题目 : 有三个线程分别打印A.B.C,请用多线程编程实现,在屏幕上循环打印10次ABCABC… package my.thread.test; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class PrintThreadExample { public static void main(String[] args) { PrintThreadExample

微软2017校招笔试题2 composition

题目 Alice writes an English composition with a length of N characters. However, her teacher requires that M illegal pairs of characters cannot be adjacent, and if 'ab' cannot be adjacent, 'ba' cannot be adjacent either. In order to meet the requiremen

一道搜狗笔试题引发的思考

一: 给定一个数组a[N],我们希望构造数组b[N],其中b[i]=a[0]*a[1]*...*a[N-1]/a[i]. 在构造过程: 1.不允许使用除法: 2.要求O(1)空间复杂度和O(n)时间复杂度: 3.除遍历计数器与a[N] b[N]外,不可使用新的变量(包括栈临时变量.对空间和全局静态变量等): void makeArray(int a[],int b[],int len) { int i,j; b[0] = 1; for(i=1;i<len;i++) { b[i] = b[i-1]

一道阿里笔试题

请把以下用于连接字符串的JavaScript代码修改为更高效的方式var htmlString = ‘ < div class=”container” > ’ + ‘ < ul id=”news-list” > ’;for (var i = 0; i < NEWS.length; i++) {htmlString += ‘ < li > < a href=”’ +NEWS[i].LINK + ‘” > +NEWS[i].TITLE + ‘ < /

详解一道C++笔试题,考察重载、覆盖、多态

C++版看到的,说是面试宝典里的题目,考察重载.覆盖.多态等概念,比较有代表性.今天早上远程辅导 Yan Wang 同学学习 Qt 时还想到了这个题目,如果你能够正确理解这个题目,说明对于 C++ 中的函数重载.覆盖.虚函数.多态等有了正确的认识.然后呢,再来学习 Qt 就顺风顺水了. 博文决赛,请给我投票:Qt Quick 图像处理实例之美图秀秀(附源码下载),谢谢. 原文地址: Qt Quick 图像处理实例之美图秀秀(附源码下载) 题目是酱紫的: #include <iostream>

关于一道游戏笔试题

如何出BOSS. 每两个小时要随机出一个BOSS提供: 随机函数unsigned int random(void), 返回值是一正随机整数, 取当前时间函数unsigned int GetCurTime(void), 返回值是开机到当前的秒数 出BOSS函数NewBoss(void). 题目是,每两个小时必定出一个,但出现的时间随机,做题时间限制十五分钟 我的答案 int number=-1; int count=0; void start(){ } void update(){ if(numb