Model Rocket Height 2007

From Progteam

Revision as of 06:15, 22 February 2008 by Hjfreyer (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Checkmark.jpg This problem has been solved by hjfreyer.


Conversions
Problem Number G
Sorter: hjfreyer
Source: GNYR ICPC 2007
Link: http://www.acmgnyr.org/year2007/G.pdf




This is problem G from the GNYR ICPC 2007


This was a pain. But kind of cool in retrospect.

{{#for: 7 |*{{#vardefine:odd|{{#expr: {{#var:odd}} + 1}}}}{{#var:odd}}}}


Code

import java.util.*;

public class Main{
    public static Scanner in;
    public static void main(String[] args){
	in = new Scanner(System.in);
	doStuff();
    }
 
    public static void doStuff(){
	int N = in.nextInt();
        double D = in.nextDouble();
	double L = in.nextDouble();
	double HA = in.nextDouble();
	double HB = in.nextDouble();
	double ERRDIST = in.nextDouble();
	for(int i = 1; i <=N; i++){
	    System.out.print(i+" ");
	    double alpha= in.nextDouble();
	    double beta= in.nextDouble();
	    double gamma= in.nextDouble();
	    double delta= in.nextDouble();
	    solve(D,L,HA,HB,ERRDIST,alpha,beta,delta,gamma);
	    
	}

    }

    public static void solve(double D, 
                             double L, 
                             double HA,
                             double HB, 
                             double ERRDIST, 
                             double alpha,                              
                             double beta, 
                             double delta, 
                             double gamma){
	if(alpha < 0 || alpha > 90 ||beta < 0 || beta > 90 || gamma < 0 || gamma > 90 || delta < 90 || delta > 180 ){
	    System.out.print("DISQUALIFIED\n");
	    
	}

	else{
	    delta = 180.0 - delta;
	    double ang =(double)( 180.0 -(delta + gamma));
	    
	    double tau = (D*Math.sin(Math.toRadians(delta)))/Math.sin(Math.toRadians(ang));
	    double SA = HA/Math.tan(Math.toRadians(alpha));
	    double L1 = SA + tau;
	    double A4 = L1*Math.tan(Math.toRadians(alpha));

	    double theta = (D*Math.sin(Math.toRadians(gamma)))/Math.sin(Math.toRadians(ang));
	    double SB = HB/Math.tan(Math.toRadians(beta));
	    double L2 = SB + theta;

	    double B4 = L2*Math.tan(Math.toRadians(beta));


	    double diff = Math.abs(A4-B4);

	    if(diff <= ERRDIST){
		int ans = (int)Math.round(diff/2 + Math.min(A4, B4));
		System.out.printf("%d\n",ans );

	    }

	    else{
		System.out.print("ERROR\n");
	    }
	}
    }
}

Personal tools