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 1793. Tray 2

java AC code
Posted by esbybb 5 Oct 2015 01:02
//package timus;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;

public class p1793 {
    public static void main(String[] args) {
        InputStream is = System.in;
        Scanner sc = new Scanner(new InputStreamReader(is));
        double a,b,h,r1,r2,R1,R2,H,rr1,rr2,x1,y1,x2,y2,D,d;
        boolean inside1,inside2;
        a = sc.nextInt();
        b = sc.nextInt();
        h = sc.nextInt();
        r1 = sc.nextInt();
        R1 = sc.nextInt();
        r2 = sc.nextInt();
        R2 = sc.nextInt();
        H = sc.nextInt();
        rr1 = R1;
        rr2 = R2;
        if (H >= h) {
            double d1,d2;
            d1 = (R1-r1)/2.0;
            d2 = (R2-r2)/2.0;
            rr1 = 2*d1 * h / H + r1;
            rr2 = 2*d2 * h / H + r2;
        }
        inside1 = 2.0 * rr1 <= a && 2.0 * rr2 <= b;
        inside2 = 2.0 * rr1 <= b && 2.0 * rr2 <= a;
        if (!inside1 || !inside2) {
            System.out.println("NO");
            return;
        }
        x1 = rr1;
        y1 = rr1;
        x2 = a - rr2;
        y2 = b - rr2;
        D = R1 + R2;
        d = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
        if (d >= D * D) {
            if ((x2 - x1 + rr1 + rr2) <= a && (y2 - y1 + rr1 + rr2) <= b)
                System.out.println("YES");
            else
                System.out.println("NO");
        } else {
            System.out.println("NO");
        }
    }

}