hihoCoder_FontSize

一、题目大意:共有N个段落,每个段落有若干个字,屏幕尺寸宽W,高H,求可以设置的最大号字体

二、代码

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class FontSize {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        HashMap<ArrayList<Integer>, ArrayList<Integer>> inputs = new LinkedHashMap<ArrayList<Integer>, ArrayList<Integer>>();
        int cases = in.nextInt();
        for (int i = 0; i < cases; i++) {
            ArrayList<Integer> para = new ArrayList<Integer>();
            for (int j = 0; j < 4; j++) {
                para.add(new Integer(in.nextInt()));
            }
            ArrayList<Integer> chara = new ArrayList<Integer>();
            for (int k = 0; k < para.get(0); k++) {
                chara.add(new Integer(in.nextInt()));
            }
            inputs.put(para, chara);
        }
        Iterator it = inputs.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry e = (Entry) it.next();
            ArrayList<Integer> para = (ArrayList<Integer>) e.getKey();
            ArrayList<Integer> chara = (ArrayList<Integer>) e.getValue();
            int maxS = 0;
            maxS = FindFont(para, chara);
            System.out.println(maxS);
        }
        in.close();
    }

    public static int FindFont(ArrayList<Integer> para, ArrayList<Integer> chara) {
        int maxS = 0;
        int S = Math.min(para.get(2), para.get(3));
        int i = S;
        for (; i > 0; i--) {
            int row = para.get(2) / i;
            int col = para.get(3) / i;
            int rownum = 0;
            for (int j = 0; j < para.get(0); j++) {
                if (chara.get(j) % row == 0) {
                    rownum += chara.get(j) / row;
                } else
                    rownum += chara.get(j) / row + 1;
            }
            if (rownum <= (para.get(1) * col))
                break;
        }
        maxS = i;
        return maxS;
    }
}

 

posted @ 2016-10-10 15:19  莫影  阅读(165)  评论(0编辑  收藏  举报