A Most Ingenious Pair a' Twins: Difference between revisions

From programming_contest
Jump to navigation Jump to search
imported>Kmk21
 
imported>Kmk21
No edit summary
 
Line 1: Line 1:
= Introduction =
This asks you to plug numbers into an equation and get the result.
= 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 ====
<syntaxhighlight line lang="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)));
}
}
}
</syntaxhighlight>
[[Category:midatl2011]]
[[Category:midatl2011]]
[[Category:ICPC Problems]]
[[Category:ICPC Problems]]
[[category:printf]]
[[Category:Algorithm Trivial]]
[[Category:Implementation Trivial]]

Latest revision as of 22:11, 4 February 2015

Introduction

This asks you to plug numbers into an equation and get the result.

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)));
		}
	}
}