ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1874. Football Goal

java AC not formula
Posted by esbybb 12 Jul 2015 09:45
package timus;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.StringTokenizer;

public class p1874 {
    static double a, b;
    public static void main(String[] args) throws FileNotFoundException {
        InputStream is = System.in;
        FastScanner sc = new FastScanner(new InputStreamReader(is));
        a = sc.nextInt();
        b = sc.nextInt();
        double XP = 0.000000001;
        double edge = 26.819279181787458*2.0;

        double l = 0, r = edge;
        while (r - l > XP) {
           double m1 = l + (r - l) / 3,
              m2 = r - (r - l) / 3;
           if (f2(m1, edge) < f2(m2,edge))
              l = m1;
           else
              r = m2;
        }
        System.out.println(String.format("%.7f",Math.min(f2(l, edge),f2(r,edge))));
    }

    static double f2(double alfa, double sum2) {
        double beta = sum2 - alfa;
        double alfaRad = Math.toDegrees(alfa);
        double betaRad = Math.toDegrees(beta);

        double A = Math.cos(alfaRad)*a;
        double B = Math.cos(betaRad)*b;

        double h = Math.sin(alfaRad)*a;
        double l = Math.sin(betaRad)*b;
        return  A*B + (A*h+B*l)/2.0;
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }

}