Submission #241536


Source Code Expand

Copy
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

/**
 * Created by hama_du on 2014/09/27.
 */
public class Main {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        long a = in.nextLong();
        long b = in.nextLong();
        long A = Math.min(a, b);
        long B = a + b - A;

        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            long c = in.nextLong();
            long d = in.nextLong();
            if (place(A, B, c, d) || place(A, B, d, c)) {
                out.println("YES");
            } else {
                out.println("NO");
            }
        }
        out.flush();
    }

    private static boolean place(long A, long B, long c, long d) {
        if (((A <= c) && (B <= d)) || ((A <= d)) && (B <= c)) {
            return true;
        }

        double min = 0.0d;
        double max = d;
        for (int x = 0 ; x < 40 ; x++) {
            double m1 = (min * 2 + max) / 3;
            double m2 = (min + max * 2) / 3;
            if (doit(A, B, c, d, m1) < doit(A, B, c, d, m2)) {
                min = m1;
            } else {
                max = m2;
            }
        }
        return (doit(A, B, c, d, min) >= B);
    }

    public static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }


    private static double doit(long a, long b, long c, long d, double X) {
        double Y = a * a - X * X;
        if (Y < 0) {
            return 0.0d;
        }
        Y = Math.sqrt(Y);

        double pc = c - X;
        double pd = d - Y;
        if (pc < 0 || pd < 0) {
            return 0.0d;
        }
        return Math.sqrt(pc * pc + pd * pd);
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int next() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

Submission Info

Submission Time
Task B - 高橋君と禁断の書
User hamadu
Language Java (OpenJDK 1.7.0)
Score 0
Code Size 4239 Byte
Status
Exec Time 403 ms
Memory 21576 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 subtask0-sample-01.txt
All 0 / 100 subtask0-sample-01.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask1-16.txt, subtask1-17.txt, subtask1-18.txt, subtask1-19.txt, subtask1-20.txt, subtask1-21.txt, subtask1-22.txt, subtask1-23.txt, subtask1-24.txt, subtask1-25.txt, subtask1-26.txt, subtask1-27.txt, subtask1-28.txt, subtask1-29.txt, subtask1-30.txt
Case Name Status Exec Time Memory
subtask0-sample-01.txt 307 ms 19796 KB
subtask1-01.txt 309 ms 19836 KB
subtask1-02.txt 331 ms 20656 KB
subtask1-03.txt 356 ms 21040 KB
subtask1-04.txt 351 ms 21136 KB
subtask1-05.txt 352 ms 21092 KB
subtask1-06.txt 354 ms 21084 KB
subtask1-07.txt 358 ms 21160 KB
subtask1-08.txt 356 ms 21100 KB
subtask1-09.txt 362 ms 21148 KB
subtask1-10.txt 381 ms 21276 KB
subtask1-11.txt 368 ms 21576 KB
subtask1-12.txt 352 ms 21292 KB
subtask1-13.txt 372 ms 21500 KB
subtask1-14.txt 363 ms 21232 KB
subtask1-15.txt 363 ms 21228 KB
subtask1-16.txt 392 ms 21288 KB
subtask1-17.txt 367 ms 21236 KB
subtask1-18.txt 369 ms 21292 KB
subtask1-19.txt 399 ms 21216 KB
subtask1-20.txt 369 ms 21264 KB
subtask1-21.txt 393 ms 21264 KB
subtask1-22.txt 403 ms 21128 KB
subtask1-23.txt 381 ms 21168 KB
subtask1-24.txt 388 ms 21188 KB
subtask1-25.txt 388 ms 21352 KB
subtask1-26.txt 388 ms 21296 KB
subtask1-27.txt 372 ms 21224 KB
subtask1-28.txt 398 ms 21368 KB
subtask1-29.txt 382 ms 21196 KB
subtask1-30.txt 389 ms 21288 KB