Contest Duration: ~ (local time) (90 minutes) Back to Home

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) {
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);
}

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

this.stream = stream;
}

public int next() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
} 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 2014-09-27 21:29:31+0900 B - 高橋君と禁断の書 hamadu Java (OpenJDK 1.7.0) 0 4239 Byte WA 403 ms 21576 KB

#### Test Cases

Set Name Score / Max Score Test Cases
Case Name Status Exec Time Memory