## 11242 - Tour de France

All about problems in Volume CXII. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

### 11242 - Tour de France

Hello,
I've got WA, Why?

Code: Select all
`import java.io.*;import java.util.*;class Main {    public static void main(String[] args) {         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1024 * 1024);        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));//        String line;        Scanner scanner = new Scanner(reader);        try {            while (scanner.hasNextInt()) {                int front = scanner.nextInt();                if (front == 0) {                    break;                }                int rear = scanner.nextInt();                int[] frontTeeths = new int[front];                int[] rearTeeths = new int[rear];                for (int i = 0; i < frontTeeths.length; i++) {                    frontTeeths[i] = scanner.nextInt();                }                for (int i = 0; i < rearTeeths.length; i++) {                    rearTeeths[i] = scanner.nextInt();                }                PriorityQueue<Double> d = new PriorityQueue<Double>();                for (int frontTeeth : frontTeeths) {                    for (int rearTeeth : rearTeeths) {                        d.add((double) rearTeeth / frontTeeth);                    }                }                PriorityQueue<Double> result = new PriorityQueue<Double>(100, new Comparator<Double>() {                    public int compare(Double o1, Double o2) {                        return o2.compareTo(o1);                    }                });                double diff = 0;                double D1 = 0, D2 = 0;                Double d1 = d.poll();                Double d2;                while (d.size() > 0) {                    d2 = d.poll();                    double newDiff = d2 - d1;                    if (newDiff > diff) {                        D1 = d1;                        D2 = d2;                        diff = newDiff;                    }                    d1 = d2;                }                writer.write(String.format("%.2f", (D2 / D1)));                writer.write("\n");            }            writer.flush();        } catch (IOException e) {        }    }}`
sith
Learning poster

Posts: 67
Joined: Sat May 19, 2012 7:46 pm

### Re: 11242 - Tour de France

Input:
Code: Select all
`2 240 4010 100`
AC output: 1.00
brianfry713
Guru

Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11242 - Tour de France

My program returns 1.0 for that input. Is this not the same thing? I did this to convert the original float to a float rounded to two decimals:

max *= 100;
max = Math.round(max);
max /= 100;

So anything that resembles this, "1.10 or 2.80 or 0.10 or 1.00 ..etc" would crop the last 0 when output. I'm using java by the way...
Any ideas?
New poster

Posts: 8
Joined: Fri Aug 10, 2012 7:48 am

### Re: 11242 - Tour de France

For each test case, output the maximum spread rounded to two decimal places. 1.00 is not judged the same as 1.0
brianfry713
Guru

Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA