排版页数


latex自然是广大研究人员最喜欢使用的科研论文排版工具之一。
月神想在iPhone 上查阅写好的paper,但是无赖iPhone 上没有月神喜欢使用的阅读软件,于是月神也希望像tex老爷爷Donald Knuth那样自己动手do it yourself一个。
在DIY这个阅读软件的过程中,月神碰到一个问题,已知iPhone屏幕的高为H,宽为W,若字体大小为S(假设为方形),则一行可放W / S(取整数部分)个文字,一屏最多可放H / S (取整数部分)行文字。
已知一篇paper有N个段落,每个段落的文字数目由a1, a2, a3,...., an表示,月神希望排版的页数不多于P页(一屏显示一页),那么月神最多可使用多大的字体呢?

import java.util.*;

public class ks_paper_tex {
	
	public static int count_page(int [] array, int count_limit, int line_limit) {
		int lines = 0;
		for(int i=0; i<array.length; i++) {
			lines += (array[i]+count_limit-1)/count_limit;
		}
		return (line_limit+lines-1)/line_limit;
	}
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int max_int = Integer.MAX_VALUE;
		int n, page_max, height, width, left, right, flag, mid;
		while(true) {
			if(scan.hasNextInt()==false) {
				break;
			}
		n = scan.nextInt();
		page_max = scan.nextInt();
		height = scan.nextInt();
		width = scan.nextInt();
		scan.nextLine();
		String [] strs = scan.nextLine().split(" ");
		int [] array = new int[n];
		int i = 0;
		for(String c: strs) {
			if(c!= " ") {
			array[i++] = Integer.parseInt(c); 
			}
		}
		
		left=1; right=width;
		flag = -1;
		mid=-1;
		while(left<right) {			
			mid = (left+right+1) >> 1;
			int count_limit = width/mid;
			int line_limit = height/mid;
			int page_count = count_page(array, count_limit, line_limit);
			//System.out.println(page_count);
			if(page_count==page_max) {flag=1; break;}
			else if(page_count<page_max) left=mid;
			else right=mid-1;
		}
		System.out.println(left);
		System.out.println(right);
		System.out.println(flag);
		if(flag>0)
		System.out.println(mid);
		else
		System.out.println(left);
		}
	}// while input
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值