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

Submission #242002

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) || place(B, A, c, d) || place(B, A, 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;
}

// {ok,ng}
double min1 = 0.0d;
double max1 = A;
for (int x = 0 ; x < 40 ; x++) {
double med = (min1 + max1) / 2;
if (isok1(A, B, c, d, med)) {
min1 = med;
} else {
max1 = med;
}
}

// {ng,ok}
double min2 = 0.0d;
double max2 = A;
for (int x = 0 ; x < 40 ; x++) {
double med = (min2 + max2) / 2;
if (isok2(A, B, c, d, med)) {
max2 = med;
} else {
min2 = med;
}
}
return (max2 < min1);
}

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

private static boolean isok1(long a, long b, long c, long d, double X) {
double Y = Math.sqrt(a * a - X * X);
double da = Y + b * X / a;
if (da > d) {
return false;
}
return true;
}

private static boolean isok2(long a, long b, long c, long d, double X) {
double Y = Math.sqrt(a * a - X * X);
double xy = Math.sqrt(X * X + Y * Y);
double db = X + b * Y / xy;
if (db > c) {
return false;
}
return true;
}

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 22:06:58+0900 B - 高橋君と禁断の書 hamadu Java (OpenJDK 1.7.0) 100 4709 Byte AC 453 ms 22576 KB

#### Test Cases

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