QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#795152 | #9804. Guess the Polygon | ucup-team3734# | Compile Error | / | / | Java11 | 4.1kb | 2024-11-30 18:07:35 | 2024-11-30 18:07:35 |
Judging History
This is the latest submission verdict.
- [2024-11-30 18:07:35]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-11-30 18:07:35]
- Submitted
answer
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
class Fraction implements Comparable<Fraction> {
private BigInteger numerator;
private BigInteger denominator;
public Fraction(int numerator, int denominator) {
this.numerator = BigInteger.valueOf(numerator);
this.denominator = BigInteger.valueOf(denominator);
simplify();
}
public Fraction(BigInteger numerator, BigInteger denominator) {
this.numerator = numerator;
this.denominator = denominator;
simplify();
}
public Fraction add(Fraction other) {
BigInteger newNumerator = this.numerator.multiply(other.denominator)
.add(other.numerator.multiply(this.denominator));
BigInteger newDenominator = this.denominator.multiply(other.denominator);
return new Fraction(newNumerator, newDenominator);
}
public Fraction subtract(Fraction other) {
BigInteger newNumerator = this.numerator.multiply(other.denominator)
.subtract(other.numerator.multiply(this.denominator));
BigInteger newDenominator = this.denominator.multiply(other.denominator);
return new Fraction(newNumerator, newDenominator);
}
public Fraction multiply(Fraction other) {
BigInteger newNumerator = this.numerator.multiply(other.numerator);
BigInteger newDenominator = this.denominator.multiply(other.denominator);
return new Fraction(newNumerator, newDenominator);
}
public Fraction divide(BigInteger divisor) {
return new Fraction(this.numerator, this.denominator.multiply(divisor));
}
private void simplify() {
BigInteger gcd = numerator.gcd(denominator);
numerator = numerator.divide(gcd);
denominator = denominator.divide(gcd);
if (denominator.compareTo(BigInteger.ZERO) < 0) {
numerator = numerator.negate();
denominator = denominator.negate();
}
}
@Override
public int compareTo(Fraction other) {
BigInteger left = this.numerator.multiply(other.denominator);
BigInteger right = other.numerator.multiply(this.denominator);
return left.compareTo(right);
}
@Override
public String toString() {
return numerator + "/" + denominator;
}
public BigInteger getNumerator() {
return numerator;
}
public BigInteger getDenominator() {
return denominator;
}
}
public class Main {
static Scanner scanner = new Scanner(System.in);
private static Fraction ask(Fraction x) {
System.out.println("? " + x.getNumerator() + " " + x.getDenominator());
System.out.flush();
int p = scanner.nextInt();
int q = scanner.nextInt();
return new Fraction(p, q);
}
private static void solve() {
int n = scanner.nextInt();
List<Fraction[]> points = new ArrayList<>();
for (int i = 0; i < n; i++) {
int x = scanner.nextInt();
int y = scanner.nextInt();
points.add(new Fraction[]{new Fraction(x, 1), new Fraction(y, 1)});
}
Collections.sort(points, (a, b) -> a[0].compareTo(b[0]));
List<Fraction> answers = new ArrayList<>(Collections.nCopies(n, new Fraction(0, 1)));
for (int i = 1; i < n - 1; i++) {
answers.set(i, ask(points.get(i)[0]));
}
Fraction S = new Fraction(0, 1);
for (int i = 0; i < n - 1; i++) {
Fraction width = points.get(i + 1)[0].subtract(points.get(i)[0]);
Fraction height = answers.get(i).add(answers.get(i + 1));
S = S.add(width.multiply(height));
}
S = S.divide(BigInteger.valueOf(2));
System.out.println("! " + S.getNumerator() + " " + S.getDenominator());
System.out.flush();
}
public static void main(String[] args) {
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
solve();
}
}
}
Details
Fraction.java:79: error: class Main is public, should be declared in a file named Main.java public class Main { ^ 1 error