/* * PolarExplorer.java * * Created on September 30, 2002, 9:41 PM */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; /** * This class is used to determine if the polar explorer will have enough * fuel to reach the alien space craft and return to the north pole. * * @author Aaron */ public class PolarExplorer { /** radius of the planet */ private static int radius; /** number of gallons of gasoline */ private static int gasoline; /** angle from the center of the earch to the space craft */ private static int angle; /** the mathematical constant PI */ public static final double PI = 3.14159; /** end of input flag */ public static final String END_OF_INPUT = "ENDOFINPUT"; /** start of data set flag */ public static final String START = "START"; /** end of data set flag */ public static final String END = "END"; /** Creates a new instance of PolarExplorer */ public PolarExplorer() { super(); } /** * Parses the input values from the input line * @param String the input line */ public static void getInputs(String line) throws Exception { StringTokenizer st = new StringTokenizer(line); if ( st.countTokens() != 3 ) { throw new Exception("Invalid input!"); } radius = Integer.parseInt( st.nextToken() ); gasoline = Integer.parseInt( st.nextToken() ); angle = Integer.parseInt( st.nextToken() ); } /** * Calculates the arc length between the explorer and * the space craft * @return int The distance to the space craft */ public static double getDistance() { if (angle > 180) { angle = 360 - angle; } double circumference = 2 * PI * radius; double arc = circumference * angle / 360; return (2 * arc); } /** * Returns the distance the explorer can travel * with the fuel he has * @return int The maximum distance he can go */ public static int getRange() { return ( gasoline * 5 ); } /** * Reads lines of input from standard in and processes * the data. */ public static void main(String args[]) { String line = null; try { BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) ); line = in.readLine(); while ( (line != null) && ( !line.trim().equals(END_OF_INPUT) ) ) { if (!line.equals(START)) { throw new Exception("Invalid data"); } line = in.readLine(); // read the line following START getInputs(line); // parse the input line double distanceToShip = getDistance(); // get the distance to the ship int maximumRange = getRange(); // get the maximum range of the explorer if (distanceToShip <= maximumRange) // compare the two values { // Yes he can make it there and back System.out.println("YES " + ((int) (maximumRange - distanceToShip) / 5) ); } else { // No he cannot make it System.out.println("NO " + maximumRange); } line = in.readLine(); if ((line == null) || (!line.equals(END))) { throw new Exception("Invalid data"); } line = in.readLine(); // read the next input line } } catch (Exception e) { e.printStackTrace(); } } }