Raggedy, Raggedy

From programming_contest
Revision as of 22:15, 4 February 2015 by imported>Kmk21 (Created page with "= Introduction = This asks you to format monospaced text by splitting it across lines of max length L such that the sum of squares of the difference between the actual line le...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

This asks you to format monospaced text by splitting it across lines of max length L such that the sum of squares of the difference between the actual line lengths and L is mininal.

Solutions

Idea

Do some basic algebra, and compute the desired result.

Gotchas

be sure to use %.3f to print to three places

Code

Solution - Java

import java.util.*;
public class a {
	Scanner in=new Scanner(System.in);
	public static void main(String[] args) {
		new a().go();
	}
	private void go() {
		while(true){
			double te=in.nextDouble(),tr=in.nextDouble();
			if(te==0&&tr==0)break;
			System.out.printf("%.3f\n", Math.sqrt((1-tr/te*tr/te)));
		}
	}
}