11242 - Tour de France

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

Moderator: Board moderators

Post Reply
sith
Learning poster
Posts: 72
Joined: Sat May 19, 2012 7:46 pm

11242 - Tour de France

Post by sith »

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) {
        }
    }
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11242 - Tour de France

Post by brianfry713 »

Input:

Code: Select all

2 2
40 40
10 10
0
AC output: 1.00
Check input and AC output for thousands of problems on uDebug!
invadrFlip
New poster
Posts: 8
Joined: Fri Aug 10, 2012 7:48 am

Re: 11242 - Tour de France

Post by invadrFlip »

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?
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11242 - Tour de France

Post by brianfry713 »

For each test case, output the maximum spread rounded to two decimal places. 1.00 is not judged the same as 1.0
Check input and AC output for thousands of problems on uDebug!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11242 - Tour de France

Post by brianfry713 »

For the sample input the possible drive ratios in ascending order are:
40 / 19 = 2.11
40 / 16 = 2.50
50 / 19 = 2.63
40 / 14 = 2.86
50 / 16 = 3.13
40 / 12 = 3.33
50 / 14 = 3.57
50 / 12 = 4.17

The spreads are:
2.50 / 2.11 = 1.19
2.63 / 2.50 = 1.05
2.86 / 2.63 = 1.09
3.13 / 2.86 = 1.09
3.33 / 3.13 = 1.07
3.57 / 3.33 = 1.07
4.17 / 3.57 = 1.17

The max is 1.19
Check input and AC output for thousands of problems on uDebug!
matrix2220
New poster
Posts: 9
Joined: Mon Jul 07, 2014 3:37 pm
Contact:

Re: 11242 - Tour de France

Post by matrix2220 »

Drive ration = rear teeth / front teeth <<<<<

Input

Code: Select all

10 10
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
10 10
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
10 10
30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49
10 10
40 41 42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57 58 59
10 10
50 51 52 53 54 55 56 57 58 59
60 61 62 63 64 65 66 67 68 69
10 10
60 61 62 63 64 65 66 67 68 69
70 71 72 73 74 75 76 77 78 79
10 10
80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99
10 10
90 91 92 93 94 95 96 97 98 99
91 92 93 94 95 96 97 98 99 100
3 5
20 30 50
100 90 80 70 60
5 3
100 90 80 70 60
20 30 50
3 4
11 13 17
13 17 19 23
2 2
40 40
10 10
0
AC Output

Code: Select all

1.05
1.03
1.03
1.02
1.02
1.01
1.01
1.01
1.17
1.17
1.31
1.00

Abdelrahman Ali (MaTrix)
Abdelrahman Ali (MaTrix)
Post Reply

Return to “Volume 112 (11200-11299)”