Google Code Jam Notes - Captain Hammer - Java
2013-12-28 00:28
477 查看
Problem:
Retrieved from: http://code.google.com/codejam/contest/2845486/dashboard#s=p1
The Hamjet is a true marvel of aircraft engineering. It is a jet airplane with a single engine so powerful that it burns all of its fuel instantly during takeoff. The Hamjet doesn't have any wings because
who needs them when the fuselage is made of a special Wonderflonium isotope that makes it impervious to harm.
Piloting the Hamjet is a not a job for your typical, meek-bodied superhero. That's why the Hamjet belongs to Captain Hammer, who is himself impervious to harm. The G-forces that the pilot endures when
taking a trip in the Hamjet are legen-dary.
The Hamjet takes off at an angle of θ degrees up and a speed of V meters per second. Vis a fixed value that is determined by the awesome power of the Hamjet engine and
the capacity of its fuel tank. The destination is D meters away. Your job is to program the Hamjet's computer to calculate θ given V and D.
Fortunately, the Hamjet's Wondeflonium hull is impervious to air friction. Even more fortunately, the Hamjet doesn't fly too far or too high, so you can assume that the Earth is flat, and that the acceleration
due to gravity is a constant 9.8 m/s2 down.
smallest positive one.
An answer will be considered correct if it is within 10-6 of the exact answer, in absolute or relative error. See the FAQ for
an explanation of what that means, and what formats of floating-point numbers we accept.
1 ≤ V ≤ 300;
1 ≤ D ≤ 10000;
It is guaranteed that each test case will be solvable.
Analysis:
This is a physics problem
V*sinx = 1/2 * g * t
V*cosx * t = D
=>x = 1/2* arcsin(gD/v^2)
My solution: (Your opinion is highly appreciated)
Retrieved from: http://code.google.com/codejam/contest/2845486/dashboard#s=p1
The Hamjet is a true marvel of aircraft engineering. It is a jet airplane with a single engine so powerful that it burns all of its fuel instantly during takeoff. The Hamjet doesn't have any wings because
who needs them when the fuselage is made of a special Wonderflonium isotope that makes it impervious to harm.
Piloting the Hamjet is a not a job for your typical, meek-bodied superhero. That's why the Hamjet belongs to Captain Hammer, who is himself impervious to harm. The G-forces that the pilot endures when
taking a trip in the Hamjet are legen-dary.
The Hamjet takes off at an angle of θ degrees up and a speed of V meters per second. Vis a fixed value that is determined by the awesome power of the Hamjet engine and
the capacity of its fuel tank. The destination is D meters away. Your job is to program the Hamjet's computer to calculate θ given V and D.
Fortunately, the Hamjet's Wondeflonium hull is impervious to air friction. Even more fortunately, the Hamjet doesn't fly too far or too high, so you can assume that the Earth is flat, and that the acceleration
due to gravity is a constant 9.8 m/s2 down.
Input
The first line of the input gives the number of test cases, T. T lines follow. Each line will contain two positive integers -- V and D.Output
For each test case, output one line containing "Case #x: θ", where x is the case number (starting from 1) and θ is in degrees up from the the horizontal. If there are several possible answers, output thesmallest positive one.
An answer will be considered correct if it is within 10-6 of the exact answer, in absolute or relative error. See the FAQ for
an explanation of what that means, and what formats of floating-point numbers we accept.
Limits
1 ≤ T ≤ 4500;1 ≤ V ≤ 300;
1 ≤ D ≤ 10000;
It is guaranteed that each test case will be solvable.
Sample
Input | Output |
3 98 980 98 490 299 1234 | Case #1: 45.0000000 Case #2: 15.0000000 Case #3: 3.8870928 |
This is a physics problem
V*sinx = 1/2 * g * t
V*cosx * t = D
=>x = 1/2* arcsin(gD/v^2)
My solution: (Your opinion is highly appreciated)
package codeJam.google.com; import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.text.DecimalFormat; /** * @author Zhenyi 2013 Dec 23, 2013 11:47:44 AM */ public class CaptainHammer { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader( "C:/Users/Zhenyi/Downloads/B-small-practice.in")); FileWriter out = new FileWriter( "C:/Users/Zhenyi/Downloads/B-small-practice.out"); int T = new Integer(in.readLine()); for (int cases = 1; cases <= T; cases++) { String[] st = in.readLine().split("\\s"); Integer V = new Integer(st[0]); Integer D = new Integer(st[1]); Double result = (Math.toDegrees((Math.asin(((9.8 * D) / (V * V))))) * 0.5); DecimalFormat form = new DecimalFormat("0.00000000"); out.write("Case #" + cases + ": " + form.format(result) + "\n"); } in.close(); out.flush(); out.close(); } }
相关文章推荐
- Google Code Jam Notes - Cross The Maze - Java
- Google Code Jam Notes - Spaceship Defence - Java
- Google Code Jam Notes - Sorting - Java
- Google Code Jam Notes - Rotate - Java
- Google Code Jam Notes - Bad Horse - Java
- Google Code Jam Notes - All Your Base - Java
- Google Code Jam Notes - Meet And Party - Java
- Google Code Jam Notes - Alien Language - Java
- Google Code Jam Notes - Rope Intranet - Java
- Google Code Jam Notes - Reverse Words - Java
- Google Code Jam Notes - Good Luck - Java
- Google Code Jam Notes - Read Phone Number - Java
- Google Code Jam Notes - Rational Number Tree - Java
- Google Code Jam Notes - Sudoku Checker - Java
- Google Code Jam Notes - Moist - Java
- Google Code Jam Notes - Dragon Maze - Java
- Google Code Jam Notes - Minimum Scalar Product - Java
- Google Code Jam Notes - Store Credit - Java
- Google Code Jam Notes - File Fix-It - Java
- Google Code Jam 资格赛: Problem A. Magic Trick